Blogger Information
Blog 15
fans 0
comment 0
visits 20766
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
ajax跨域问题
李子的博客
Original
722 people have browsed it

原生ajax请求方式:
var xhr = new XMLHttpRequest();  
xhr.open("POST", "http://xxxx.com/demo/b/index.php", true);  
xhr.withCredentials = true; //支持跨域发送cookiesxhr.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");



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post