我想調用外部網站webmethod,併發布一些數據。我嘗試了很多不同的方式,仍然無法獲得被調用的方法。使用jsonp調用外部網站webmethod?
這裏是我的js代碼:
$.ajax({
url: "http://sitename.com/methods.aspx/mywebmethod",
data: "{'id':'" + 4 + "'}",
dataType: "jsonp",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
這裏是我的webmethod代碼:
[WebMethod()]
public static bool mywebmethod(int id)
{
if(id != 0){
return true;}
else{return false;}
}
,我總是得到相同的響應
Error: jQuery{code} was not called
我失去了什麼?
我該如何發佈數據? – Steven 2012-04-03 16:29:32
你不能。您需要了解JSONP的工作方式。 http://en.wikipedia.org/wiki/JSONP – SLaks 2012-04-03 16:34:16
任何其他發佈數據的方式?不使用JSONP! – Steven 2012-04-03 16:35:30