1
제 문제는 다음 코드가 Firefox와 Chrome에서는 잘 작동하지만 IE9에서는 작동하지 않습니다. 위치가 정의되지 않았거나 null입니다. 다음과 같이자동 완성이 IE9에서 인식되지 않습니다.
내 자동 완성 코드는 다음과 같이
$("#id_location").autocomplete({
source: function(request, response) {
$.ajax({
url: "{% url 'food.views.search_location' %}",
dataType: "json",
data:{
maxRows: 5,
starts_with: request.term,
},
success: function(data) {
response($.map(data.location, function(item) {
return {
label: item.label,
value: item.value
}
}));
}
});
},
minLength: 1,
focus: function(event,ui){
//prevent value insert on focus
$("#id_location").val(ui.item.label);
return false; //Prevent widget from inserting value
},
select: function(event, ui) {
$('#id_location').val(ui.item.label);
$('#id_locationID').val(ui.item.value);
return false; // Prevent the widget from inserting the value.
},
});
내 backened 코드는 다음과 같습니다
def search_location(request):
"""
Jason data for location
search autocomplete
"""
q = request.GET['starts_with']
r = request.GET['maxRows']
ret = []
listlocation = USCities.objects.filter(name__istartswith=q)[:r]
for i in listlocation:
ret.append({'label':i.name+','+i.state.name+' '+i.state.abbr,'value':i.id})
ret = {'location':ret}
data = simplejson.dumps(ret)
return HttpResponse(data,
content_type='application/json; charset=utf8'
)
도움말 크게 감사하겠습니다!
이starts_with: request.term,
이 객체 구조의 마지막 요소이며, 끝에 쉼표가 있습니다
어디에서 위치가 정의되지 않거나 null이됩니까? 서버 측 또는 JS? 또한 오류가 발생한 코드의 정확한 위치를 알 수 있습니까? – Babu