asp.net – 如何使用jquery“jsonp”调用外部Web服务?
|
我之前有一个问题 can jquery ajax call external webservice? 一些优秀的开发人员回答我使用jsonp,但我不知道如何使用它,我试图使用此代码调用我的服务: $.ajax({
type: "POST",url: "http://localhost:1096/MySite/WebService.asmx?callback=?",data: "{}",contentType: "application/json; charset=utf-8",dataType: "jsonp",success: function(msg) {alert(msg);}
});
这是我的服务代码: [WebMethod]
public string HelloWorld() {
return "Hello World " ;
}
任何人都有例子或可以为我解释这个问题? 更新: $.getJSON("http://localhost:1096/YourShoppingTest1/WebService.asmx/HelloWorld?jsonp=?",{name:"test"},function(data){
alert(data.x);
});
和这样的服务: [WebMethod]
public string HelloWorld(string name)
{
return "( {"x":10,"y":100} )";
}
但它总是在回来时给我这个错误:“丢失;在声明之前 并且从不调用成功函数,任何人都可以帮忙吗? 解决方法我有一个类似的问题,不幸的是我没有手头的代码.从记忆里: >将[ScriptService]作为属性添加到Web方法中 见:What are some good examples of JQuery using JSONP talking to .net?& What is the best way to call a .net webservice using jquery? (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
