views:

182

answers:

1

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/"&gt;[{"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

A: 

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()
Nick Craver
Here ia how my web method looks like <WebMethod()> _ <ScriptMethod(UseHttpGet:=False, ResponseFormat:=ResponseFormat.Json)> _ Public Function GetCUList(ByVal q As String) As StringWhat would I need to change here ?
SidK
@SidK - Try changing `dataType: 'jsonp'` to `dataType: 'xml'` and see how it handles it.
Nick Craver