我如何获得使用JQuery从服务(WCF)返回的值?
问题描述:
客户端:我如何获得使用JQuery从服务(WCF)返回的值?
$("#btn").click(function (event) {
$.getJSON('http://host/myservice.svc/GetCount?method=?', { Id: '2' }, function (customer) {
//how to get an value ??? here ????
});
//return false;
});
服务器
public long GetCount(string method, string Id)
{
return 100;
}
答
你有JSONP端点自动转换并发送JSONP对象给用户。 如果jsonP你应该得到直接。
如果它不是jsonp端点,请将您的后端更改为具有jsonP表示法的格式良好的字符串,然后在UI中进行评估。
您将有一些跨浏览器的问题also.follow以下链接
http://www.west-wind.com/weblog/posts/107136.aspx
自定义JSONP绑定
<endpoint address="ajax" binding="customBinding" bindingConfiguration="jsonpBinding" behaviorConfiguration="JsonBehavior" contract="InterfaceGoeshere"/>
您是如何定义JSONP端点? – 2010-11-22 21:33:44