數據以JSON形式作爲數組返回。在本文檔中的例子,如果你看一下JS代碼:
$.ajax({
dataType: "jsonp"
...
.then(function(response) { // <-- this expects response as a JSON object
$.each(response,function(i,val){ // <-- each iterates over the array, i is the index, val is the value
html+="<li>"+val+"</li>"; //<-- creates the HTML for the autocomplete
})
事實上,你可以使用Chrome的谷歌開發者工具查看響應。在這個例子中,如果你寫「啤酒」你:
jQuery1102023577826283872128_1446566971852(["Aledo, IL, United States","Aledo, MU, Spain","Aledo, TX, United States","Aleknagik, AK, United States","Aleppo, HL, Syria","Aleppo, PA, United States","Alert, NT, Canada","alesund, MR, Norway","Alex, OK, United States","Alexander City, AL, United States","Alexander, AR, United States","Alexander, IA, United States","Alexander, IL, United States","Alexander, KS, United States","Alexander, NC, United States","Alexander, ND, United States","Alexander, NY, United States","Alexandra Headland, QL, Australia","Alexandra Hills, QL, Australia","Alexandra, GT, South Africa"]);
你可以試用此例的URL中使用的變量q
傳遞一個查詢作爲參數:
http://gd.geobytes.com/AutoCompleteCity?q=abe
對不起,我有問題複製這個,你可以看看這個其他問題:http://stackoverflow.com/questions/33834280/cant-replicate-jquery-mobile-autocomplete-demo – IMB