ie9 ajax post cookie,ie9 ajax跨域withCredentials不发送cookie

浏览器发送xhr但没有cookie(凭据)

以下代码在http://first_domain.local运行

$.ajaxSetup({

type: "POST",

cache: false,

crossDomain: true,

data: {},

dataType: 'json',

xhrFields: {

withCredentials: true

}

});

jQuery.support.cors = true;

$.ajax({

cache: false,

async: true,

crossDomain: true,

url: "http://second_domain.local",

beforeSend: function(xhr) {

xhr.withCredentials=true;

},

type: "POST",

data: {},

dataType: "JSON",

success: function(res, textStatus, xhr) {

},

error: function (xhr, ajaxOptions, thrownError) {

}

});

php服务器上的

设置:

$http_origin = $_SERVER['HTTP_ORIGIN'];

header('Access-Control-Allow-Credentials: true');

header('Access-Control-Allow-Methods: GET, POST, OPTIONS');

header('Access-Control-Allow-Headers: Authorization');

header('Access-Control-Allow-Origin: *');

header('Access-Control-Allow-Origin: '.$http_origin.'');

header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

它在IE 10,11 friefox和chrome中完美运行

DZh5N.png

AIagL.png

解答:

在这个问题上似乎有2个意见:

这是不可能的

使用MoonScript lib

醇>

两者都有效,因为"无法在IE9及更早版本中制作跨域ajax请求并发送cookie。"

BUT! MoonScript诀窍(不知何故),它适用于我。

所以我建议你试试MoonScript

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值