|
本帖最后由 sakawinki 于 2015-3-1 01:27 编辑
本人亲测直接调用以下四种方法都只能局限于X5自身站点:
1、$.get 2、$.post 3、$.ajax 4、$.getJSON为什么呢?
网上查来查去,发现这个方式确实可以用X5连自己的后台,拿.net举例:
asp.net页面地址:http://localhost:26242/Index.aspx
核心内容:
protected void Page_Load(object sender, EventArgs e)
{
string kk=Request.QueryString["jsoncallback"];
Response.Write(kk + "([{'WebEngineInfo':'WEB SERVICE ENGINE IS RUNNING','TimeAt':'" + DateTime.Now.ToString() + "'}])");
}
X5中的代码:
$.getJSON("http://localhost:26242/Index.aspx?jsoncallback=?",
{ id:"0", action:"xxxjson"},
function(json) {
alert(json[0].WebEngineInfo);
});
又测试了:
$.ajax({
"type" : "post",
"async" : false,
"dataType" : "json",
"contentType" : "application/json",
"url" : "http://localhost:26242/Index.aspx?jsoncallback=?", //this.BASE_URL + this.QUERY_URL,
"data" : JSON.stringify(ajaxData),
"success" : function(json) {
alert(json[0].WebEngineInfo);
for (var i = 0, len = querys.length; i < len; i++) {
var query = querys;
var maps = json[query.queryName];
var table = self.maps2table(maps, query.data.defCols);
query.data.loadData(table);
query.data.first();
}
if (success && $.isFunction(success)) {
success.call(this, json);
}
},
"error" : error ? error : this.errorProcesser
});
非常好用!!!
【关键点】
总之前台请求时传递的jsoncallback和后台服务页的Request.QueryString["jsoncallback"]是关键参数,没有就不能跨域。而且后台得到的Request.QueryString["jsoncallback"]必须加在返回值前面才行。
感觉有点像一种通讯的回执校验一样。
|
评分
-
查看全部评分
|