我需要在change country-province-city
上自动刷新选择值这似乎很容易,但是当事件发生时,请在第一时间呼叫退出 一些代码:
使用Javascript:
$('#id_province_es').change(function(){
if ($('#id_province_es').val() == 0){
console.info("don't do nothing");
}
else{
var data = $('#id_province_es').val();
console.info(data);
$.ajax({
type: 'GET',
url: "/city/"+data,
dataType: 'json',
success: function(data) {
var options = '<option value="">{% trans "Selecciona una ciudad" %}</option>';
for (var i = 0; i < data.length; i++){
options += '<option value="'+data[i][0]+'">' +data[i][1] +'</option>'
}
$('#id_city_es').html(options)
},
error: function () { console.error("error al cargar las ciudades")};
});}});
Django的:
def refreshCities(request,province):
client = WSDL_CLIENT # Client(settings.WSDL_URL
data = ""
try:
cities = client.service.getCities(province)
citiesList = []
for p in cities:
citiesList.append((p.pkCity, _(p.name)))
except BaseException as e:
o4aException = One4allCoreException(e)
messages.add_message(request, messages.ERROR, o4aException)
try:
data = json.dumps(citiesList)
except BaseException as e:
pass
return HttpResponse(data, mimetype="application/javascript")
我的chrome日志。我做了两次改变。首先注销,第二个没关系
[22/Nov/2012 13:21:24] "GET /city/2/ HTTP/1.1" 302 0
[22/Nov/2012 13:23:25] "GET /accounts/logout/ HTTP/1.1" 302 0
[22/Nov/2012 13:23:26] "GET / HTTP/1.1" 302 0
[22/Nov/2012 13:23:26] "GET /accounts/login/?next=/ HTTP/1.1" 200 7399
[22/Nov/2012 13:24:04] "GET /city/2 HTTP/1.1" 301 0
[22/Nov/2012 13:49:58] "GET /city/2/ HTTP/1.1" 200 16
有什么想法吗?