Determine if the request header contains a property to determine if it is an AJAX request _ajax related

Source: Internet
Author: User
Copy code code as follows:

<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");
//jquery Yui sends an HTTP request header message with Http_x_requested_with by default, so you can determine if Ajax is requested by determining whether the request header contains this property
Xmlhttp.setrequestheader (' Http_x_requested_with ', ' http_x_requested_with ');
Xmlhttp.send ();

Xmlhttp.onreadystatechange=function ()
{
if (xmlhttp.readystate==4 && xmlhttp.status==200) br>{
Alert (xmlhttp.responsetext);
}
{
}

</script>
<body>
<input type= "button" id= "BT" Name= "BT" value= "OK" oncLick= "cl ();"/>
</body>
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.