How to determine whether there is an attribute in the request header to determine whether it is an ajax request
This article shows you how to judge whether the request header contains an attribute to determine whether it is an ajax request, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
The code is as follows:
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 a HTTP request header message with HTTP_X_REQUESTED_WITH by default, so you can determine whether the ajax request is made by determining whether the attribute is contained in the request header.
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)
}
}
}