Ajax Communication Principles Xmlhttprequest_ajax Related

Source: Internet
Author: User
Obviously Ajax is a technique for accessing data using JavaScript scripts.
AJAX enables the Web page to implement asynchronous updates. This is the local updating of the Web page without reloading the entire page.
XMLHttpRequest is the key to AJAX
Browsers now support XMLHttpRequest objects (IE5 and IE6 use ActiveXObject).
Request data back to the readystate has five states 0: Server uninitialized, 1: Server connection established, 2 requests accepted, 3 request processing, 4 request complete.
Every change of state is a good trigger once onreadystatechange event, status has two states: "OK", 404: "Page not Found"
Here's an AJAX foreground implementation code:
Copy Code code as follows:

<title> Untitled Page </title>
<script type= "Text/javascript" >
function GetName () {
var xmlhttp;
if (window. XMLHttpRequest) {
Xmlhttp=new XMLHttpRequest ();
}else{
Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
}
Xmlhttp.onreadystatechange=function () {
if (xmlhttp.readystate==4 && xmlhttp.status==200) {
Alert ("Hello:" +xmlhttp.responsetext);
}
}
Xmlhttp.open ("Post", "Default.aspx?id=gname", true);
Xmlhttp.send ();
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<div> <input id= "Button1" type= "button" value= "button" onclick= "GetName ()"/></p>
</div>
</form>
</body>

Background code:
Copy Code code as follows:

protected void Page_Load (object sender, EventArgs e)
{
if (request["id"]!=null)
{
Response.Write ("John");
Response.End ();
}
}

Execution result: Figure below

Download attachment code next time, let's see how jquery is requesting data asynchronously.
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.