JavaScript AJAX Requests

Source: Internet
Author: User

Ajax asynchronous transfer value in JS

<script type= "Text/javasccript" >

var xmlHttp;

function Createxmlrequest ()

{

IE browser

if (window. ActiveXObject)

Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");

Non-IE browser

else if (window. XMLHttpRequest)

Xmlhttp=new XMLHttpRequest ();

}

function Startreadystate ()

{

Createxmlrequest ();

Xmlhttp.onreadystatechange=handlerstatechange;

Xmlhttp.open ("GET", "default.aspx?") Name= "+escape (document.getelementbyidx_x_x (" Txtname "). Value), true);

Xmlhttp.send (NULL);

}

function Handlerstatechange ()

{

if (xmlhttp.readystate== "4" && xmlhttp.status== "200")

{

if (xmlhttp.responsetext== "Zhangsan")

{

Document.getelementbyidx_x_x ("Label1"). Innertext=xmlhttp.responsetext;

}

}

}

</script>

Note:

GET:

Returnmethod method that is called after a successful return

Xmlhttp.onreadystatechange=returnmethod;

Xmlhttp.open ("GET", "default.aspx?") Name= "+escape (name), true);

Xmlhttp.send (NULL);

POST:

var para= "Name=" +escape (Name);

Xmlhttp.onreadystatechange=returnmethod;

Xmlhttp.open ("POST", "default.aspx", true);

To use post async be sure to add the following statement

Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded;");

Xmlhttp.send (para);

In the Default.aspx.cs page

If using the post asynchronous value, want to use ResponseText in JS to receive the value,

Must be clear first with response.clear ()

Response.Write ("Zhangsan");

Then use Response.End () to output from memory;

With get asynchronous handed down also can not response.clear ();

JavaScript AJAX Requests

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.