1. Different browsers
Create an XMLHTTPRequest object(General functions)
<SCRIPT type = "text/JavaScript">
Function ajaxfunction ()
{
VaR
XMLHTTP ;
Try
{
// Firefox, opera 8.0 +, Safari
XMLHTTP = new XMLHttpRequest ();
}
Catch (E)
{
// Internet Explorer
Try
{
// IE 6.0 +
XMLHTTP = new activexobject ("msxml2.xmlhttp ");
}
Catch (E)
{
Try
{
// IE 5.5 +
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Catch (E)
{
Alert ("your browser does not support Ajax! ");
Return false;
}
}
}
}
</SCRIPT>
2. One
Simple AjaxProgramExample
<HTML>
<Body>
<SCRIPT type = "text/JavaScript">
Function ajaxfunction ()
{
VaR
XMLHTTP ;
Try
{
// Firefox, opera 8.0 +, Safari
XMLHTTP = new XMLHttpRequest ();
}
Catch (E)
{
// Internet Explorer
Try
{
XMLHTTP = new activexobject ("msxml2.xmlhttp ");
}
Catch (E)
{
Try
{
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Catch (E)
{
Alert ("your browser does not support Ajax! ");
Return false;
}
}
}
XMLHTTP.Onreadystatechange = Function ()
{
// 4 indicates that the request has been completed
If (
XMLHTTP.Readystate = 4)
{
Document. myform. Time. value =
XMLHTTP.Responsetext ;
}
}
XMLHTTP.Open ("get", "Time. asp", true);
XMLHTTP.Send (null);
}
</SCRIPT>
<Form name = "myform">
User: <input type = "text" name = "username"
Onkeyup= "Ajaxfunction ();" />
Time: <input type = "text" name = "time"/>
</Form>
</Body>
</Html>
This is "time. Code :
<%
response. expires =-1 // The page is not cached.
response. write (time)
%>