[英]How Can I get the data from one domain to another domain using ajax jsonp?
例如:我的网站网址为"http://localhost:54887/CustomOrdering.html"
但我想从另一个网站"http://localhost:27746/Orders.aspx"
获取数据。为此,我在CustomOrdering.html
写道
function SessionLogin() {
$.ajax({
type: "GET",
dataType: "jsonp",
contentType: "application/json",
async: false,
url: 'http://localhost:27746/Orders.aspx/SessionLogin',
success: function (msg) {
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
}
在Orders.aspx中
public void SessionLogin()
{
HttpContext.Current.Response.ContentType = "application/json";
string qs = HttpContext.Current.Request.QueryString["callback"];
HttpContext.Current.Response.Write(qs+ "( [{ \"x\": 10, \"y\": 15}] )");
}
我收到错误jQuery11110002214477863162756_1449484451326 was not called
在控制台中显示错误消息“未捕获的SyntaxError:意外的令牌<”,然后单击它指向Orders.aspx设计页面开始” 错误图像
另一个服务器需要使用给定的回调名称包装返回值:
public void SessionLogin()
{
HttpContext.Current.Response.ContentType = "application/json";
string qs = HttpContext.Current.Request.QueryString["callback"];
HttpContext.Current.Response.Write( qs + "( [{ \"x\": 10, \"y\": 15}] )");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.