Create a JS file of the XMLHTTPRequest object (applicable to ASP, PHP, JSP, Asp.net, etc)
Ajax. js
Function Ajax ()
{
VaR XMLHTTP = NULL;
If (window. XMLHttpRequest)
{// Non-ie kernel Browser
XMLHTTP = new XMLHttpRequest ();
}
Else if (window. activexobject)
{// Ie kernel Browser
Try
{// Ie6.0
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Catch (E1)
{
Try
{
XMLHTTP = new activexobject ("msxml2.xmlhttp ");
}
Catch (E2)
{
Try
{
XMLHTTP = new activexobject ("msxml3.xmlhttp ");
}
Catch (E3)
{
Alert ("failed to Create Ajax:" + E3)
}
}
}
}
Else
{// Unknown Browser
Alert ("Unrecognized browsers ");
}
Return XMLHTTP;
}
Go to the page where you want to create an object.
<Script language = "JavaScript" type = "text/JavaScript" src = "Ajax. js"> </SCRIPT>
Example of ASP
<Script language = "JavaScript" type = "text/JavaScript" src = "Ajax. js"> </SCRIPT>
<Script language = "JavaScript" type = "text/JavaScript">
VaR XMLHTTP = new Ajax ();
Function checkname ()
{
XMLHTTP. onreadystatechange = getname;
XMLHTTP. Open ("get", "getname. asp", true );
XMLHTTP. Send (null)
}
Function getname ()
{
VaR dom = Document. getelementbyid ("name ")
If (XMLHTTP. readystate = 1)
{
Dom. value = "connecting to the server"
}
Else if (XMLHTTP. readystate = 2 | XMLHTTP. readystate = 3)
{
Dom. value = "reading data ";
}
Else if (XMLHTTP. readystate = 4)
{
If (XMLHTTP. Status = 200)
{
Dom. value = XMLHTTP. responsetext
}
}
}
</SCRIPT>