我將自動填充數據源更改爲我的php文件,並且我嘗試了下面的代碼。但這不是工作,有人可以建議如何解決它?jQuery建議自動完成列表未顯示
感謝
$('#search').autocomplete({
source: function(request, response) {
$.ajax({
url: "/property_bldg.php",
dataType: "jsonp",
data: {
query: request.term
},
success: function(data) {
response($.map(data.suggestions, function(item) {
return {
label: item.text,
value: item.text
}
}));
}
});
},
minLength: 1
})
返回
{query:'A',par1:'',suggestions:['AUSTIN RD','ARCH','ARGYLE ST','AMOY GDN','ARIA','AQUAMARINE','ACADEMIC TERR','APEX','ALLWAY GDN','AP LEI CHAU DRIVE'],data:[]}
更新時間:
$('#autocomplete_propSearch').autocomplete({
source: function(request, response) {
$.ajax({
url: "/property_bldg.php",
dataType: "json",
data: {
query: request.term
},
complete: function (xhr, status) {
if (status === 'error' || !xhr.responseText) {
alert('Error')
}
else {
response($.map(xhr.responseText.suggestions, function(item) {
return {
label: item,
value: item
}
}));
}
}
});
},
minLength: 1
})
你在firebug或javascript控制檯中得到的錯誤 – Satya
@Satya沒有錯誤,所以我不知道錯在哪裏 –