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