The reason why Ajax, get, and post parameters are passed and readystate is always 0 (16:33:12)
Reprinted token
Tags: it reason control code browser |
Category: Ajax |
VaR XMLHTTP;
VaR htmltext;
// Obtain the "XMLHTTP" control through browser compatibility
Function getxmlrequster (){
Try {
If (window. activexobject ){
For (VAR I = 5; I>-1; I --){
Try {
If (I = 2)
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
Else
XMLHTTP = new activexobject ("Microsoft. XMLHTTP." + I + ". 0 ");
Break;
}
Catch (e ){
XMLHTTP = false;
}
}
}
Else if (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ();
}
}
Catch (e ){
XMLHTTP = false;
}
};
// Obtain the "XMLHTTP" control through browser compatibility
// Send it to the background
Function databand (indexnum ){
Getxmlrequster ();
// Problem
XMLHTTP. onreadystatechange = xmlhttp_onreadystatechange;
// (XMLHTTP. onreadystatechange = xmlhttp_onreadystatechange ();
// XMLHTTP. onreadystatechange assigns the returned value of xmlhttp_onreadystatechange
// XMLHTTP. onreadystatechange; while XMLHTTP. onreadystatechange is called when the status changes
// Use the xmlhttp_onreadystatechange function to write
// XMLHTTP. onreadystatechange = xmlhttp_onreadystatechange; if there is a parameter, // write:
// XMLHTTP. onreadystatechange = functiong () {xmlhttp_onreadystatechange // (a, B );};)
XMLHTTP. Open ("get", "Left. aspx? Id = "+ escape (indexnum), true); // escape encoding of the get Method
XMLHTTP. Send (null); //
XMLHTTP. Open ("Post", "Left. aspx", true); // POST method
XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded"); // POST method, a required sentence for post
XMLHTTP. Send ("ID =" + indexnum); // POST method
}
// Send it to the background
// Judge the delivery
Function xmlhttp_onreadystatechange (){
If (XMLHTTP. readystate = 4 ){
If (XMLHTTP. Status = 200 ){
Htmltext = XMLHTTP. responsetext;
}
Else {
}
}
Else {
}
}
// Judge the delivery
// Background
// Use request. Form ["ID"] for the post method
If (request. Form ["ID"]! = NULL)
{
String indexnum = server. urldecode (request. Form ["ID"]);
If (indexnum = "1 ")
Response. write ("<p> <a href =' # '> 1 </a> </P> <p> <a href =' # '> 1 </a> </P> <p> <a href = '#'> dasfads </a> </P> <p> <a href =' # '> 1 </A> </P> ");
Else if (indexnum = "2 ")
Response. write ("<p> <a href =' # '> 2 </a> </P> <p> <a href =' # '> 2 </a> </P> <p> <a href = '#'> dasfads </a> </P> <p> <a href =' # '> 2 </A> </P> ");
Response. End ();
}
// Request. querystring ["ID"] For the get Method
If (request. querystring ["ID"]! = NULL)
{
String indexnum = server. urldecode (request. querystring ["ID"]);
If (indexnum = "1 ")
Response. write ("<p> <a href =' # '> 1 </a> </P> <p> <a href =' # '> 1 </a> </P> <p> <a href = '#'> dasfads </a> </P> <p> <a href =' # '> 1 </A> </P> ");
Else if (indexnum = "2 ")
Response. write ("<p> <a href =' # '> 2 </a> </P> <p> <a href =' # '> 2 </a> </P> <p> <a href = '#'> dasfads </a> </P> <p> <a href =' # '> 2 </A> </P> ");
Response. End ();
}
Share: