AJAX sends a request to the server

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.