Ajax supports two data submission methods: Get and post.

Source: Internet
Author: User

Ajax supports two data submission methods: Get and post. The post method can transmit data larger than 2 K. The differences in Ajax applications are: "the request address of the POST method and the transmitted data are put in two objects-the request address is put in the open object, and the transmitted data is placed in the send object; before transmitting data, define a transmission file HTTP header (setRequestHeader )"

Reference content is as follows:
<Script language = "JavaScript">
Function saveuserinfo (){
// Obtain the accept response information layer
VaR MSG = Document. getelementbyid ("MSG ");
VaR F = Document. user_info;
VaR username = f. user_name.value;
VaR userage = f. user_age.value;
VaR usersex = f. user_sex.value;
// URL of the received form
VaR url = "Commit. php ";
// The post value is required to connect each variable through &
VaR poststr = "name =" + username + "& age =" + userage + "& sex =" + usersex;
// Instantiate Ajax
VaR Ajax = NULL;
If (window. XMLHttpRequest ){
Ajax = new XMLHttpRequest ();
}
Else if (window. activexobject ){
Ajax = new activexobject ("Microsoft. XMLHTTP ");
}
Else {
Return;
}
// Open the connection through post
Ajax. Open ("Post", URL, true );
// Define the HTTP header information of the transmitted File
Ajax. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
// Send post data
Ajax. Send (poststr );
// The processing function of the returned data
Ajax. onreadystatechange = function (){
If (Ajax. readystate = 4 & Ajax. Status = 200 ){
MSG. innerhtml = Ajax. responsetext;
}
}
}
</SCRIPT>
<Form name = "user_info">
Name: <input type = "text" name = "user_name"/> <br/>
Age: <input type = "text" name = "user_age"/> <br/>
Gender: <input type = "text" name = "user_sex"/> <br/>
<Input type = "button" value = "Submit Form" onclick = "saveuserinfo ()">
</Form>
// Construct a layer for receiving returned information:
<Div id = "MSG"> </div>

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.