使用 JQuery UI 自动完成显示不显示结果
我正在使用 Jquery UI 的自动完成功能,并且可以在 Firebug 中看到返回的正确 JSON 数据。但是,文本框中没有任何内容。
我的 JavaScript:
$(function() {
function log( message ) {
$( "<div/>" ).text( message ).prependTo( "#log" );
}
$("#tags").autocomplete({
source: function(request, response){
$.ajax ({
url: "/projectlist",
dataType: "json",
data: {style: "full", maxRows: 12, term: request.term}
});
}
})
});
您可以从代码片段中看到正在返回 JSON 数据。但结果表中没有显示任何内容。它应该类似于 JQuery 自动完成示例 JQuery 自动完成
I'm using Jquery UI's autocomplete, and I can see the proper JSON data coming back in Firebug. However, nothing's coming back to the textbox.
My JavaScript:
$(function() {
function log( message ) {
$( "<div/>" ).text( message ).prependTo( "#log" );
}
$("#tags").autocomplete({
source: function(request, response){
$.ajax ({
url: "/projectlist",
dataType: "json",
data: {style: "full", maxRows: 12, term: request.term}
});
}
})
});
You can see that from the snippet JSON data is being returned. But nothing is being displayed in the results table. Which should look like the the JQuery autocomplete example JQuery Autocomplete
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显示 Noyhing 是因为您没有返回任何内容,我认为:您必须将成功函数添加到您的 ajax 调用中(我添加了成功响应的示例,如果您告诉我们您的 json 是如何构造的,我可以更好地帮助您。无论如何,您必须返回一个对象数组,每个对象应该有一个名为“label”的属性和一个名为“value”的属性:
我在这里设置了一个小提琴:http://jsfiddle.net/nicolapeluchetti/pRzTy/ (假设“data”是返回的 json )
Noyhing is displayed because you return nothing i think: you must add e success function to your ajax call (i added an example of a success response, if you tell us how your json is tructured i could help you better. in any case you must return an array of objects, and each object should have a property named 'label' and one named 'value':
I set up a fiddle here: http://jsfiddle.net/nicolapeluchetti/pRzTy/ (imagine that 'data' is the json that is returned)