The X-requested-with request header is used on the server to determine whether a request comes from an Ajax request or a traditional request.
The two types of requests have different headers. Ajax asynchronous requests have one more header parameter than traditional synchronous requests.
1. Traditional synchronous Request Parameters
Accept text/html, application/XHTML + XML, application/XML; q = 0.9, */*; q = 0.8
Accept-charset gb2312, UTF-8; q = 0.7, *; q = 0.7
Accept-encoding gzip, deflate
Accept-language ZH-CN, ZH; q = 0.5
Cache-control Max-age = 0
Connection keep-alive
Cookie JSESSIONID = 1a3bed3f593ea9747c9fda16d309af6b
Host 192.168.101.72: 8080
Keep-alive 300
Referer xxx
User-Agent Mozilla/5.0 (windows; U; Windows NT 5.1; ZH-CN; RV: 1.9.0.15) Gecko/2009101601 Firefox/3.0.15 (. net clr 3.5.30729)
2 Ajax asynchronous request Method
Accept */*
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;. Net CLR 2.0.50727;. Net CLR 3.0.04506.648;. Net CLR
Host 192.168.101.72: 8080
Content-Length 233
Connection keep-alive
Cache-control no-Cache
Cookie CSS = undefined; JSESSIONID = 1b9ac25036290f7fb6823cce1a24e541
The Ajax request contains x-requested-with, and the request. getheader ("X-requested-with") can be obtained ")
Bool isajax = NULL;
String header = request. getheader ("X-requested-");
If (null! = Header & header. Equals ("XMLHttpRequest "))
{
Isajax = true;
}
We can see that if the header is null, It is a traditional synchronous request. If XMLHttpRequest is used, it is an Ajax request.
Original post address: http://www.cnblogs.com/tony-jingzhou/archive/2012/07/30/2615612.html