当前位置: 首页 » 产品 » 生活保健 » 正文

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

放大字体  缩小字体 发布日期: 2024-09-29 19:31   来源:http://www.baidu.com/  作者:无忧资讯  浏览次数:15
核心提示:  1、原生ajax请求方式:  1 var xhr=new XMLHttpRequest();  2 xhr.open(POST, , true);  3 xhr.withCredentials=true;

  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: ");

 
 
[ 产品搜索 ]  [ 加入收藏 ]  [ 告诉好友 ]  [ 打印本文 ]  [ 违规举报 ]  [ 关闭窗口 ]

 

 
推荐图文
推荐产品
点击排行
    行业协会  备案信息  可信网站