Ajaxfun. js (call a function)
Function createxmlhttprequest ()
{
Try
{
XMLHTTP = new XMLHttpRequest ();
Return XMLHTTP;
}
Catch (trymicrosoft)
{
Try
{
XMLHTTP = new activexobject ("msxml2.xmlhttp ");
Return XMLHTTP;
}
Catch (othermicrosoft)
{
Try
{
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
Return XMLHTTP;
}
Catch (failed)
{
Return XMLHTTP;
}
}
}
If (! XMLHTTP)
{
Return false;
}
}
Function getresponsetext (method, URL, OBJ)
{
XMLHTTP = createxmlhttprequest ();
If (XMLHTTP = NULL)
{
Return "[Error]";
}
XMLHTTP. Open (method, URL );
XMLHTTP. onreadystatechange = function ()
{
If (4 = XMLHTTP. readystate)
{
If (200 = XMLHTTP. Status)
{
OBJ. innerhtml = XMLHTTP. responsetext;
}
}
}
XMLHTTP. Send ();
}
Test.html
<Script language = JavaScript src = "ajaxfun. js"> </SCRIPT>
<Input type = "text" name = "username" size = "20">
<Div id = "usernamehint"> </div>
<Script language = "JavaScript" for = "username" event = "onblur">
OBJ = Document. getelementbyid ("username ");
Objhint = Document. getelementbyid ("usernamehint ");
Getresponsetext ('get', 'test. asp? Username = '+ obj. Value, objhint)
</SCRIPT>
Test. asp is used for verification. It is the same as the common ASP syntax for request. querystring.