文章正文

Ajax跨域访问header中 x-requested-with丢失

【文章】2020-04-23

简介Ajax跨域访问header中 x-requested-with丢失

前端调用后端接口,本域情况下,ajax方式调用,request header中包含x-requested-with信息。

image.png

跨域情况下,request header中不再包含x-requested-with。
说明:
1.前端ajax封装的jquery的$.ajax方法。
2.后端header相关设置已允许接收x-requested-with。
3.尝试手动设置header,失败

$.ajax({        
        url:'http://b.com/index.php',        //url:'test.php',
        type:'GET',        
        data:data,        
        dataType:'json',        
        headers:{            
            "Access-Control-Allow-Headers":"Origin, Content-Type, Cookie, Accept",            
            "Content-Type" : "multipart/form-data,application/x-www-form-urlencoded; charset=UTF-8",             
            "X-Requested-With":"XMLHttpRequest"
        },        
        xhrFields:{            
            withCredentials:true
        }, 
        success:function(res){            
            console.log(res);
        },
})

打赏支持

感谢您的支持,加油!

打开微信扫码打赏,你说多少就多少

找书费时,联系客服快速获取!

扫码支持

在线客服8:30-22:30,若离线请留言!

获取教程,请联系在线客服!

扫码支持

在线客服8:30-22:30,若离线请留言!

热门阅读

找PDF电子书,太费时间?

  • 微信扫描二维码,让客服快速查找。
  • 在线客服8:30-22:00,若离线请留言!