X-Requested-With常用于判断是不是ajax请求
但是有时我们会有需要删除X-Requested-With的情况
下面介绍一种方式 js代码
复制代码 代码如下:
$.ajax({
url: 'http://',
beforeSend: function( xhr ) {
xhr.setRequestHeader('X-Requested-With', {toString: function(){ return ''; }});
},
success: function( data ) {
if (console && console.log){
console.log( 'Got data without the X-Requested-With header' );
}
}
});
附,判断ajax请求的方式 java代码
复制代码 代码如下:
if (request.getHeader("x-requested-with") != null
&& request.getHeader("x-requested-with").equalsIgnoreCase("XMLHttpRequest")) {
//异步请求
}else{
}
如何从jQuery的ajax请求中删除X-Requested-With
2021-05-18 21:14:27声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。 如涉及版权问题,请提交至online#300.cn邮箱联系删除。
热门文章