我使用协议 jsonp 来调用 web 方法。
我将此代码用于网络服务:
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod]
public string HelloWorld()
{
return "Hello World";
}
}
这在 Jquery 和客户端的 jason 上:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: 'http://localhost:50837/Service1.asmx/HelloWorld',
data: {},
dataType: "json",
success: function(Msg) {
alert('success:' + Msg.d.FirstName);
},
error: function(xhr, textStatus, errorThrown) {
alert("error");
}
});
}
这个 Jquery 总是给我一个错误信息,但我不知道原因。有人可以帮助我吗?