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>