gpt4 book ai didi

javascript - 带有 json 的 Jquery 自动完成失败

转载 作者:行者123 更新时间:2023-11-30 09:07:42 29 4
gpt4 key购买 nike

我正在使用 Devbridge 的自动完成插件我已经全部安装在这里是我的代码:

$(document).ready(function(){
$('#request_task').autocomplete({
serviceUrl: '<%= ajax_path %>',
minChars:1,
width: 300,
delimiter: /(,|;)\s*/,
deferRequestBy: 0, //miliseconds
params: { artists: 'Yes' },
});

});

此请求命中我的 rails 操作并返回此 json。只有一个对象被返回,但大多数时候会有超过 1 个...这只是一个测试用例:

[
{
"user": {
"salt": "somthing",
"name": "john",
"encrypted_password": "92dadsfa6b001ffe71c3c1d8e9fb76c42d1c8afeffa739de9063d94206c",
"created_at": "2010-09-10T14:10:54Z",
"updated_at": "2010-09-10T14:10:54Z",
"admin": null,
"id": 1,
"remember_token": "c945522b3eb0a25e36bb39155fc05b3eec301ac5e2196956f2e6f86b4b22c987",
"email": "test@gmail.com"
}
}
]

我可以清楚地看到 Firebug 中的请求,但我没有得到任何自动完成的东西,它出错了……我是不是遗漏了什么……我的错误是

a.suggestions is undefined

最佳答案

我认为您需要进一步阅读开发人员页面,因为您的回复格式错误:

Web page that provides data for Ajax Autocomplete, in our case autocomplete.ashx will receive GET request with querystring ?query=Li, and it must return JSON data in the following format:

{
query:'Li',
suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania'],
data:['LR','LY','LI','LT']
}

Notes:

query - original query value
suggestions - comma separated array of suggested values data
(optional) - data array, that contains values for callback function when data is selected.

关于javascript - 带有 json 的 Jquery 自动完成失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3686292/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com