我将自动完成数据源更改为我的 php 文件,并尝试了下面的代码。但它不起作用,有人可以建议如何解决它吗?
谢谢
$('#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
})