博客列表 >ajax跨域问题

ajax跨域问题

李子的博客
李子的博客原创
2019年03月14日 11:04:56710浏览

原生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");



声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议