Ajax get post

Source: Internet
Author: User
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:
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.