Talking about Ajax

Source: Internet
Author: User

One. What is Ajax?

Ajax is read without flush data.

Two. The principle of Ajax:

HTTP request method

1.get-used to get data (e.g. Browse posts)

2.post-for uploading data (e.g., user registration)

Three. Writing the AJAX request:

The idea of Ajax requests

1. Creating an Ajax Object

IE6 or more

var oajax=new xmlhttprequest ();

IE6

var oajax=new activexobject ("Microsoft.XMLHTTP");

Resolving IE6 compatibility issues

var oajax=null;

if (window. XMLHttpRequest)
{
Oajax=new XMLHttpRequest ();
}
Else
{
Oajax=new ActiveXObject ("Microsoft.XMLHTTP");
}

2. Linked Servers

Open (method, URL, whether asynchronous)
Oajax.open (' GET ', ' abc.txt ', true);//Where abc.txt is the path

3. Sending the request

Oajax.send ();

4. Receive return

Oajax.onreadystatechange=function ()
{
if (oajax.readystate==4)
{
if (oajax.status==200)
{
Alert (' success: ' +oajax.responsetext);
}
Else
{
Alert (' failure ');
}
}
};
};

which

Request Status Monitoring

onReadyStateChange Events

ReadyState Properties: Request Status

>0 (uninitialized) has not yet called the Open () method

>1 (load) called the Send () method, sending the request

>2 (loading complete) the Send () method completed, received all response content

>3 (parsing) parsing response content

>4 (completion) Response content resolution completed, you can invoke the Status property on the client: request result ResponseText

Status property: Request result

ResponseText

Talking about Ajax

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.