2015-11-03 35 views

回答

1

数据以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 
+0

对不起,我有问题复制这个,你可以看看这个其他问题:http://stackoverflow.com/questions/33834280/cant-replicate-jquery-mobile-autocomplete-demo – IMB

相关问题