欢迎来到山村网

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

2019-03-09 12:11:46浏览:815 来源:山村网   
核心摘要:  1、原生ajax请求方式:  1 var xhr = new XMLHttpRequest();  2 xhr.open(POST, http://xxxx.com/demo/b/index.php, tru

  1、原生ajax请求方式:

  1 var xhr = new XMLHttpRequest();

  2 xhr.open("POST", "http://xxxx.com/demo/b/index.php", true);

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

  4 xhr.send();

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

  $.ajax({

  type: "POST",

  url: "http://xxx.com/api/test",

  dataType: 'json',

  // 允许携带证书

  xhrFields: {

  withCredentials: true

  },

  // 允许跨域

  crossDomain: true,

  success:function(){

  },

  error:function(){

  }

  })

  3、服务器端设置:

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

  header("Access-Control-Allow-Origin: http://www.xxx.com");

(责任编辑:豆豆)
下一篇:

宽带怎么查询上网时间

上一篇:

阿尔法路由器升级方法

  • 信息二维码

    手机看新闻

  • 分享到
打赏
免责声明
• 
本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们 xfptx@outlook.com