帮助使用jQuery自动完成和JSON响应 [英] Help with jquery autocomplete and json response
本文介绍了帮助使用jQuery自动完成和JSON响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个返回以下响应的一个ASP.NET 2.0的JSON Web服务
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?
感谢
推荐答案
这不是JSON :)这是一个JSON字符串包裹在XML。呦需要让你的WebMethod返回JSON,而不是XML的。
That's not JSON :) That's a JSON string wrapped in XML. Yo need to make your WebMethod return JSON instead of XML.
例如装饰你的WebMethod:
For example decorate your WebMethod:
[WebMethod, ScriptMethod]
public List<thing> GetCUList()
这篇关于帮助使用jQuery自动完成和JSON响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文