AJAX sends a request to the server
Ajax-sends a request to the server
Send-Off requests to the server, we use the open () method and the Send () method.
The open () method has three arguments. The first parameter defines a method that uses a Send request (get or post). The second parameter specifies the URL server-side script. The request specified by the third parameter should be processed asynchronously. The Send () method sends a request to shut down the server. If we assume that HTML and ASP files are in the same directory, the code will be:
Xmlhttp.open ("Get", "time.asp", true);
Xmlhttp.send (NULL);
Now, we have to decide when Ajax functions should be performed. We will let the feature run "behind the scenes" when the user type is something of the User name text field:
<form name= "MyForm" >
Name: <input type= "Text"
Onkeyup= "Ajaxfunction ();" name= "username"/>
Time: <input type= "text" name= "Time"/>
</form>
Our latest Ajax-ready "testajax.htm" file now looks like this:
{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 ()
{
if (xmlhttp.readystate==4)
{
Document.myform.time.value=xmlhttp.responsetext;
}
}
Xmlhttp.open ("Get", "time.asp", true);
Xmlhttp.send (NULL); }</script><form name= "MyForm" >
Name: <input type= "Text"
Onkeyup= "Ajaxfunction ();" name= "username"/>
Time: <input type= "text" name= "Time"/>
</form></body>