Ajax X-requested-with Request Header

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.