如何使用ajax jsonp将数据从一个域获取到另一个域? [英] How Can I get the data from one domain to another domain using ajax jsonp?
问题描述
EX:我的网站网址http:// localhost:54887 / CustomOrdering.html但我想从其他网站获取数据http:// localhost:27746 / Orders.aspx。为此,我在CustomOrdering.html中写道
EX: My site url "http://localhost:54887/CustomOrdering.html" but I want to get data from another site "http://localhost:27746/Orders.aspx". For this I wrote in 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);
}
});
}
订单.aspx中的
in Order.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。如何从aspx页面获取上述html页面的结果。请建议我紧急
Showing error " Jquery11110002214477863162756_1449484451326 was not called" . How can I get the result for the above html page from aspx page. Please suggest me it's urgent
推荐答案
.ajax({
type: GET,
dataType: jsonp,
contentType: application / json,
async: false ,
url:' http:// localhost :27746 / Orders.aspx / SessionLogin',
成功:功能(msg){
},
错误: function (jqXHR,textStatus,errorThrown){
alert(errorThrown);
}
});
}
.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); } }); }
订单.aspx中的
in Order.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。如何从aspx页面获取上述html页面的结果。请建议我这是紧急的
Showing error " Jquery11110002214477863162756_1449484451326 was not called" . How can I get the result for the above html page from aspx page. Please suggest me it's urgent
这篇关于如何使用ajax jsonp将数据从一个域获取到另一个域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!