ajax的请求和普通的http请求,在header里面多了个参数X-Requested-With
所以可以根据这个来区分。
X-Requested-With请求头用于在服务器端判断request来自Ajax请求还是传统请求。
两种请求在请求的Header不同,Ajax 异步请求比传统的同步请求多了一个头参数
1 传统同步请求参数
accept text/html,application/xhtml+xml,application/xml;q=0.9,**
accept-language zh-cn
referer xxx
x-requested-with XMLHttpRequest
content-type application/x-www-form-urlencoded,text/javascript
accept-encoding gzip, deflate
user-agent Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; QQDownload 598
host 192.168.101.72:8080
content-length 233
connection Keep-Alive
cache-control no-cache
cookie CSS=undefined; JSESSIONID=1B9AC25036290F7FB6823CCE1A24E541
可看到Ajax请求多了个x-requested-with,可以获取request.getHeader("X-Requested-With")
bool isAjax = null;
String header = request.getHeader("X-Requested-With");
if(null != header && header.equals("XMLHttpRequest"))
{
isAjax = true;
}
可以看到header为null则为传统同步请求。若为XMLHttpRequest则为Ajax请求。
refurl:http://woshixy.blog.51cto.com/5637578/976695
相关推荐
X-Requested-With常用于判断是不是ajax请求 但是有时我们会有需要删除X-Requested-With的情况 下面介绍一种方式 js代码 代码如下: $.ajax({ url: ‘http://www.zhangruifeng.com’, beforeSend: function( xhr ) { ...
XMLHttpRequest对象 深入理解 XMLHttpRequest对象
add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS; if ($request_method = 'OPTIONS') { return 204; } } }
response.setHeader("Access-Control-Allow-Headers", "Origin,X-Requested-With,Content-Type,Accept,Authorization,token"); // System.out.println("*********************************过滤器被使用************...
<param-value>token,Access-Control-Allow-Origin,Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value> --> <param-value>Access-Control...
<param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified</param-value> </init-param> <init-param> <param-name>cors.exposedHeaders</param-name> <param-value>Set-Cookie</param...
<param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified</param-value> </init-param> <init-param> <param-name>cors.exposedHeaders</param-name> <param-value>Set-Cookie</param...
<param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified</param-value> </init-param> <init-param> <param-name>cors.exposedHeaders</param-name> <param-value>Set-Cookie</param-...
<param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified</param-value> </init-param> <init-param> <param-name>cors.exposedHeaders</param-name> <param-value>Set-Cookie</param...
< param-value > Accept, Origin, X-Requested-With, Content-Type, Last-Modified </ param-value > </ init-param > < init-param > < param-name > cors.exposedHeaders </ param-name > < param-value ...
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; if ($request_method = 'OPTIONS') { ...
Access-Control-Allow-Headers: X-Requested-With, X-Prototype-Version, Content-Type, X-Redmine-API-KeyAccess-Control-Allow-Methods: OPTIONS, GET, POST, PUT, DELETEAccess-Control-Allow-Origin: *您可以安
PocCreator GET和POST请求的POC创建者。 您只需要编辑脚本,然后选择输出文件夹,然后添加请求格式,例如Burp或Fiddler,例如本例: * ------------------------'''POST /... charset = UTF-8 X-Requested-With:X
jsonpipe 是一个轻量级的 AJAX 客户端... "X-Requested-With": "XMLHttpRequest" }, "data": "" // String. A serialized string to be sent in a POST/PUT request }); 标签:eBayjsonpipe
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, access-control-allow-methods"); res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE...
jRaiser 1.3.4 wath's new: 在$.util.parseTpl中添加容错处理,当模板为null时返回undefined,当values为空时返回模板内容。 优化了各种样式操作。... 在$.ajax.send的Ajax请求中增加X-Requested-With的header。
jQuery 发出 ajax 请求时,会在请求头部添加一个名为 X-Requested-With 的信息,信息内容为:XMLHttpRequest 在后端可以使用 $_SERVER[“HTTP_X_REQUESTED_WITH”] 来获取。(注意:中划线换成了下划线,不区分大小...
allowHeaders: 默认'Content-Type, Content-Length, Accept, X-Requested-With' allowMethods: 默认'PUT, POST, GET, DELETE, OPTIONS' } 插件 关闭CSRF防范,避免本地测试时报invalid csrf token错误 增加yhsd...
CORS 插件这个插件为 Scala Play 添加了支持! 框架应用程序。特征为对应用程序的所有请求提供飞行前 OPTIONS 响应。 提供一个 Play 过滤器,它将所..."Access-Control-Allow-Headers" -> "x-requested-with,content-ty