国-都道府県の変更時に選択した値を自動更新する必要があります
簡単に思えますが、イベントが発生したら、最初に呼び出してログアウトします。いくつかのコード:
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")
そして私のクロムログ。私は2倍の変更を行います。最初にログアウトし、2 番目に問題ありません
[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
何か案が?