我搜索的術語「雙」應該返回一個用戶名與初始「雙...」 但沒有任何顯示,沒有下拉這是我的代碼。Django沒有響應ajax自動完成
search.html
<html>
<div class="ui-widget">
<label for="search4">search4: </label>
<input id="search4">
</div>
<script type="text/javascript">
$(function(){
$("#search4").autocomplete({
source: '/rating/searchresult/',
minLength: 2,
});
});
</script>
</html>
url.py
url(r'^searchresult/', 'rating.views.search_images'),
views.py
def search_images(request):
if request.is_ajax():
s = request.GET.get("term", '')
search_result = UploadImage.objects.filter(user__username__icontains = s)[:20]
search = []
for result in search_result:
json_d = {}
json_d['id'] = result.id
json_d['name'] = result
json_d['value'] = result
search.append(json_d)
data = m_json.dumps(search)
else:
data = 'error'
mimetype = 'application/json'
return HttpResponse(data, mimetype)
如果我搜索一個值阿賈克斯而術語URL中
[04/Aug/2016 08:48:46] "GET /rating/searchresult/?term=bi HTTP/1.1" 200 2661
經過多年平均值響應並返回任何在下拉菜單中,我能不明白的地方是阿賈克斯或者Django的 Also my content type is text html see here
嘗試調試它。您可以嘗試使用'print'和'alert'語句快速檢查數據丟失的位置。 –
我試過'打印數據'和'打印s',沒有顯示任何內容 –
然後在Django中如果不打印數據,那麼Ajax Resopnse明顯會出現抖動。 –