本文介绍了jQueryUIautocomplete不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jqueryUI自动完成功能,该功能将从后端源获取可用标签.这是我的代码.

I'm trying to use jqueryUI autocomplete feature where the available tags will be fetched from the backend source.Here is my code.

HTML代码

<div class="span4 pull-right" id="search">
    Search : <input type="text" placeholder="Search">
</div>

js代码

<script>
    $(function() {
    $( "#search" ).autocomplete({
    source: "/dashboard/search"
    });
});
</script>

** django views.py **

** django views.py**

def search(request):
    availableTags = ["ActionScript","AppleScript","Asp","BASIC","C","C++","Clojure","COBOL","ColdFusion","Erlang"];
    ctx = {"availableTags":availableTags}
    return HttpResponse(availableTags) #returns the set of values(checked with firebug while debugging) but autocomplete doesnot works.

    #return render(request, 'dashboard/dashboard.html', ctx) // returns nothing.

仪表板urls.py

urlpatterns = patterns('modules.energy.dashboard.views',
    url(r'^$','dashboard',name='cilantro_dashboard'),
    url(r'search','search',name='cilantro_search'),
)

主要urls.py

urlpatterns = patterns('',

    url(r'^dashboard/', include('modules.energy.dashboard.urls')),
)

这是我在使用Firebug进行调试时收到的响应.

Here is what I receive in response while debugging with firebug.

ActionScriptAppleScriptAspBASICCC++ClojureCOBOLColdFusionErlang

我的availabletags已返回,但是自动完成功能仍然无法使用.我要去哪里错了?

My availabletags are returned but autocomplete still not works. Where I'm going wrong?

推荐答案

似乎您需要在发送数据字典之前将其转换为JSON.

Seems like you need to convert the data dict to JSON before sending it.

from django.utils import simplejson
data = simplejson.dumps(availableTags)
return HttpResponse(data)

这篇关于jQueryUIautocomplete不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 17:04