如何从jQuery的ajax请求中删除X-Requested-With
更新时间:2013年12月11日 17:48:21 作者:
X-Requested-With常用于判断是不是ajax请求,ajax请求中删除X-Requested-With的方法如下,感兴趣的朋友可以参考下
X-Requested-With常用于判断是不是ajax请求
但是有时我们会有需要删除X-Requested-With的情况
下面介绍一种方式 js代码
$.ajax({
url: 'http://www.zhangruifeng.com',
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{
}
但是有时我们会有需要删除X-Requested-With的情况
下面介绍一种方式 js代码
复制代码 代码如下:
$.ajax({
url: 'http://www.zhangruifeng.com',
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 ready函数、css函数及text()使用示例
想必大家对jquery的ready函数、css函数、text()并不陌生吧,其实很好理解的,接下来有个不错的示例,如果你对此理解还是很模糊可以参考下2013-09-09
jQuery EasyUI 开源插件套装 完全替代ExtJS
JQuery爱好者们的福音 jQuery EasyUI 开源插件套装 完全替代ExtJS(引用)2010-03-03
基于jquery的finkyUI插件与Ajax实现页面数据加载功能
基于jquery的finkyUI插件与Ajax实现页面数据加载功能,需要的朋友可以参考下。2010-12-12


最新评论