技术员联盟提供win764位系统下载,win10,win7,xp,装机纯净版,64位旗舰版,绿色软件,免费软件下载基地!

当前位置:主页 > 教程 > 服务器类 >

Ajax跨域请求COOKIE无法带上的完美怎么解决

来源:技术员联盟┆发布时间:2017-05-28 12:46┆点击:

  1、原生ajax请求方式:

  1 var xhr = new XMLHttpRequest();

  2 xhr.open("POST", "", true);

  3 xhr.withCredentials = true; //支持跨域发送cookies

  4 xhr.send();

  2、jquery的ajax的post方法请求:

  $.ajax({

  type: "POST",

  url: "",

  dataType: 'json',

  // 允许携带证书

  xhrFields: {

  withCredentials: true

  },

  // 允许跨域

  crossDomain: true,

  success:function(){

  },

  error:function(){

  }

  })

  3、服务器端设置:

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

  header("Access-Control-Allow-Origin: ");