IE8,IE9 下 ajax 访问问题解决

 

调用方式如下

$.ajax({
url: requrl,
type: "GET",
cache: false,
dataType: "json",
success: function (data) {
reqback(data);
},
});

 

$.ajax({
url: requrl,
type: "POST",
data: {id:0},
cache: false,
dataType: "json",
success: function (json, status, xhr) {
if (reqback)
reqback(json, xhr);
else
json.code === 0 ? ajax.success(json, true) : ajax.error(json, true);
},
});

 

代码如上,本以为是代码出问题,结果后面查阅资料发现,IE8还不支持CORS协议,即后台添加的Access-Control-Allow-Origin:*

解决方法如下:

  • 在$.ajax前面添加jQuery.support.cors=true;
  • 或者,在$.ajax中添加
crossDomain:true,
dataType:'jsonp',
jsonp:'callback',
posted @ 2020-12-17 11:03  断剑重铸之日  阅读(156)  评论(0编辑  收藏  举报