[英]How to resolve jquery auto complete issue
Autocomplete is not working using jquery.I tried but not working.使用 jquery 无法自动完成。我试过但没有工作。 Autocomplete values is coming from json.If i type some words then related words should be display like dropdown but not working.I am not able to find the mistake from my code.Anyone can resolve this issue?自动完成值来自 json。如果我输入一些词,那么相关词应该像下拉菜单一样显示但不起作用。我无法从我的代码中找到错误。任何人都可以解决这个问题?
https://jsfiddle.net/583seq1h/2/ https://jsfiddle.net/583seq1h/2/
$("#suggest").autocomplete({
delay: 10,
source: function (request, response) {
// Suggest URL
var suggestURL = "http://testingurl.com/complete/search.htm";
// JSONP Request
$.ajax({
method: 'GET',
dataType: 'jsonp',
jsonpCallback: 'jsonCallback',
url: suggestURL
})
.success(function(data){
response(data[1]);
});
}
});
HTML: HTML:
<input type="text" placeholder="type something ..." id="suggest" />
search.htm:搜索.htm:
{
"results":[
{
"name":"Japan",
"type":"suggest"
},
{
"name":"Malesiya",
"type":"suggest"
},
{
"name":"China",
"type":"suggest"
},
{
"name":"USA",
"type":"suggest"
},
{
"name":"canada",
"type":"suggest"
}
]
}
You have a non-existant web address in use.您有一个不存在的网址正在使用中。
var suggestURL = "http://testing.com/complete/search.json";
The json you have linked in this variable does not exist (redirects to a chinese 404).您在此变量中链接的 json 不存在(重定向到中文 404)。
var suggestURL = "http://suggestqueries.com/complete/search.json";
Additionally the json file you have linked in your post also does not exist (domain has not been renewed)此外,您在帖子中链接的 json 文件也不存在(域尚未更新)
Also, you will get a "Blocked loading mixed active content" error whilst testing in jsfiddle, so you may want to consider testing your code by a different method.此外,在 jsfiddle 中进行测试时,您将收到“阻止加载混合活动内容”错误,因此您可能需要考虑使用不同的方法测试您的代码。
Try to return
data after success
: success
后尝试return
数据:
$("#suggest").autocomplete({
delay: 10,
source: function (request, response) {
// Suggest URL
var suggestURL = "http://suggestqueries.com/complete/search.json";
// JSONP Request
$.ajax({
method: 'GET',
dataType: 'jsonp',
jsonpCallback: 'jsonCallback',
url: suggestURL
})
.success(function(data){
return response(data[1]);
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.