Determines whether the request header contains an attribute to determine whether the request is an ajax request.

Source: Internet
Author: User

Copy codeThe Code is as follows:
<Html>
<Head>
<Script language = "javascript">

Function cl ()
{
Var xmlhttp;

If (window. XMLHttpRequest)
{
Xmlhttp = new XMLHttpRequest ();
}
Else
{
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}


Xmlhttp. open ("POST", "ajax2.html", true );
Xmlhttp. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded ");
// By default, jquery YUI sends an HTTP request header message containing HTTP_X_REQUESTED_WITH. Therefore, you can determine whether an ajax request contains this attribute by checking whether the request header contains this attribute.
Xmlhttp. setRequestHeader ('HTTP _ X_REQUESTED_WITH ', 'HTTP _ X_REQUESTED_WITH ');
Xmlhttp. send ();

Xmlhttp. onreadystatechange = function ()
{
If (xmlhttp. readyState = 4 & xmlhttp. status = 200)
{
Alert (xmlhttp. responseText );
}
}
}

</Script>
</Head>
<Body>
<Input type = "button" id = "bt" name = "bt" value = "OK" onclick = "cl ();"/>
</Body>
</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.