Ajax Post method submission data __ajax

Source: Internet
Author: User

<script language= "JavaScript" >
<!–

function Saveuserinfo ()
{
Get the Accept return information layer
var msg = document.getElementById ("msg");

Get form objects and user information values
var f = document.user_info;
var userName = F.user_name.value;
var userage = F.user_age.value;
var usersex = F.user_sex.value;

Receive the URL address for the form
var url = "commit.php";
The value of the post is required to join each variable by &
var poststr = "Name=" + userName + "&age=" + userage + "&sex=" + usersex;

Instantiating Ajax
var ajax = null;
if (window. XMLHttpRequest) {
Ajax = new XMLHttpRequest ();
}
else if (window. ActiveXObject) {
Ajax = new ActiveXObject ("Microsoft.XMLHTTP");
}
else{
Return
}

To open a connection by post
Ajax.open ("POST", url, True);
Defines the transmitted file HTTP header information
Ajax.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Send post data
Ajax.send (POSTSTR);

Returns the processing function of the 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/>
Sex: <input type= "text" name= "User_sex"/><br/>
<input type= "button" value= "Submitting form" onclick= "Saveuserinfo ()" >
</form>

Build a layer that accepts return information:
<div id= "MSG" ></div>

Note :
compared to the Get method, the Post method transmits data larger than 2K, and the application in Ajax differs in that: "The Post method's request address and the transmitted data are placed in two objects-the request address is placed in the open object, The transmitted data is placed in the Send object, and a transmission file HTTP header information (setrequestheader) is defined before the data is transmitted (commit.php), which can be $_post[' name '] ,  in the file with the variable $_ post[' age '],    $_post[' sex ' obtains data transmitted by the Send object. and manipulate the database.

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.