Help with jquery autocomplete and json response

若如初见. 提交于 2019-12-25 01:53:15

问题


I have the a ASP.NET 2.0 json web service that returns the following response

<?xml version="1.0" encoding="utf-8" ?> 
  <string xmlns="http://microsoft.com/webservices/">[{"CUName":"Raytown-Lee\u0027s Summit Comm CU","CUCity":"RAYTOWN","CUState":"MO","CUContractNo":"02406"},{"CUName":"Summit Credit Union","CUCity":"MADISON","CUState":"WI","CUContractNo":"04800"},{"CUName":"Summit Credit Union","CUCity":"GREENSBORO","CUState":"NC","CUContractNo":"03200"},{"CUName":"Summit Hampton Roads FCU","CUCity":"NORFOLK","CUState":"VA","CUContractNo":"04504"},{"CUName":"SummitOne Federal CU","CUCity":"OGDEN","CUState":"UT","CUContractNo":"14301"}]</string>

When I bind this to my test box for use with the autocomplete plugin, I don't see any results in the dropdown. I checked with firebug that the call is made.

My front end call looks like below

$(document).ready(function() {
 $("#city").autocomplete("CUList.asmx/GetCUList", {
  dataType: 'jsonp',
  parse: function(data) 
  {
   var rows = new Array();
   for(var i=0; i<data.length; i++){
    rows[i] = { data:data[i], value:data[i].CUName, result:data[i].CUName };
   }
   return rows;
  },
  formatItem: function(row, i, n) {
   return row.CUName + ', ' + row.CUCity;
  },
  max: 50
 }); 
  });

Can someone please let me know what I am doing wrong?

Thanks


回答1:


That's not JSON :) That's a JSON string wrapped in XML. Yo need to make your WebMethod return JSON instead of XML.

For example decorate your WebMethod:

[WebMethod, ScriptMethod]
public List<thing> GetCUList()


来源:https://stackoverflow.com/questions/2389187/help-with-jquery-autocomplete-and-json-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!