jQueryUIautocomplete not working

我的梦境 提交于 2019-12-11 09:09:29

问题


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

HTML CODE

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

js code

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

** 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.

dashboard urls.py

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

main urls.py

urlpatterns = patterns('',

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

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

ActionScriptAppleScriptAspBASICCC++ClojureCOBOLColdFusionErlang

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


回答1:


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)



回答2:


From what I can see and if your returned results are right, that may simply be because you are returning the autocomplete in your div, and not in your input.



来源:https://stackoverflow.com/questions/19466749/jqueryuiautocomplete-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!