AJAX XMLHttpRequest Object Instance Tutorial

Source: Internet
Author: User

AJAX XMLHttpRequest Object Instance Tutorial

Ajax-More about X-ML HttpRequest objects
In sending data to the server, we have explained three important feature XMLHttpRequest objects.

Ajax onReadyStateChange
After requesting to the server, we need a feature that can receive data that is returned by the server.

onreadystatechange Property stores your functionality and will react to the process from a server.

It is not a method that functions are stored in property that is called automatic running. The following code sets the onReadyStateChange property and an empty function inside the store:
Xmlhttp.onreadystatechange=function ()
{
We are going to write some code here
}
The Ajax ReadyState property's ReadyState property owns the response of the state server.

Each time the readystate changes, the onreadystatechange function will be executed.

The following are the possible values for the ReadyState property:

State Description

0 Request not initialized

1 requirements have been established

2 Request Sent

3 Request one in the process

4 Operation complete

We want to add a declaration if the onReadyStateChange function is tested,

If our reaction is complete (which means we can get our data): Xmlhttp.onreadystatechange=function ()
{
if (xmlhttp.readystate==4)
{
Get the data from the server ' s response
}
}
ResponseText
These data are transmitted back from the server and can be responsetext with the property.

In our code, we will set the value of the "Time" input field equal to ResponseText:

Xmlhttp.onreadystatechange=function ()
{
if (xmlhttp.readystate==4)
{
Document.myform.time.value=xmlhttp.responsetext;
}
}

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.