1

我需要自动刷新选择值 onchange 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")};  
  });}});

姜戈:

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 日志。我做了两次改变。首先注销,然后就ok了

[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

任何想法?

4

0 回答 0