Ajax跨域請求COOKIE無法帶上的解決辦法


原生ajax請求方式:
var xhr = new XMLHttpRequest();  
xhr.open("POST", "http://xxxx.com/demo/b/index.php", true);  
xhr.withCredentials = true; //支持跨域發送cookies
xhr.send();

jquery的ajax的post方法請求:
 $.ajax({
               type: "POST",
               url: "http://xxx.com/api/test",
               dataType: 'jsonp',
               xhrFields: {
                      withCredentials: true
              },
            crossDomain: true,
           success:function(){
     },
           error:function(){
    }
})
服務器端設置:
 
        
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: http://www.xxx.com");

 原文出處:Ajax跨域請求COOKIE無法帶上的解決辦法


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM