jquery autocompleteui不使用远程数据

2024-09-30 00:40:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我花了两天时间在这个插件上,但是没有成功-只在本地数据数组上工作:( 我有一个代码(django/python)可以生成json字符串(valid-tested on http://jsonlint.com/),如下所示:

[{"id": 7626, "value": "Jaros\u0142aw", "label": "Adrianowicz"}, {"id": 2702, "value": "Bo\u017cena", "label": "Baranowicz"}, {"id": 2542, "value": "Tomasz", "label": "Baranowicz"}]

我的jquery代码是:

^{pr2}$

我检查了ajax示例-geonames-这个工作正常。有什么帮助吗?在


Tags: 数据django字符串代码插件idjsonvalue
2条回答

您可以在autocomplete中使用任何.ajax选项。试试这个

$('#query').autocomplete({
 source: "/aut/",   //this generate json and working
 dataType: "json",
 minLength: 2
 });

对于source的值,您可以使用回调而不是页面的url,如下例所示:

http://jqueryui.com/demos/autocomplete/#remote-with-cache

使用回调允许您为.ajax编写自己的成功和错误处理。您可能希望使用.ajax并检查错误。在

相关问题 更多 >

    热门问题