欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Ajax跨域請(qǐng)求COOKIE無(wú)法帶上的完美解決辦法

 更新時(shí)間:2017年04月17日 11:43:12   投稿:mrr  
這篇文章主要介紹了Ajax跨域請(qǐng)求COOKIE無(wú)法帶上的解決辦法,需要的朋友可以參考下

1、原生ajax請(qǐng)求方式:

1 var xhr = new XMLHttpRequest(); 

2 xhr.open("POST", "

3 xhr.withCredentials = true; //支持跨域發(fā)送cookies

4 xhr.send();

2、jquery的ajax的post方法請(qǐng)求:

$.ajax({
    type: "POST",
    url: "http://xxx.com/api/test",
    dataType: 'json',
    // 允許攜帶證書
    xhrFields: {
       withCredentials: true
    },
    // 允許跨域
    crossDomain: true,
    success:function(){
    },
    error:function(){
  }
})

3、服務(wù)器端設(shè)置:

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

以上所述是小編給大家介紹的Ajax跨域請(qǐng)求COOKIE無(wú)法帶上的完美解決辦法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論