Ajax Post Get method submission data detailed

Source: Internet
Author: User
Tags php tutorial

Ajax has two ways of submitting data, get and post, respectively. The Post method can transmit 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, and the transmitted data is placed in the Send object." ; and define a transmission file HTTP header information (setRequestHeader) before transferring data

The use of the loop is to the data before sending a reasonable processing, to solve the script language in the data processing additional requirements of the timeout phenomenon. In the knowledge of Ajax is not deep, if it is wrong or not in place, please advise.

The Post method in Ajax has three parameters, the first two parameters are required, and the third parameter depends on the requirements. The red part of the picture below, if your own code is UTF8 can not be used. Because Ajax itself defaults to the transfer value and itself is encoded with UTF8, if you are using GBK encoding, you need to transfer the code before the data transfer.

  

However, in the server processing language, the corresponding transcoding coordination is needed, such as

<script language= "Web Effects" >
function Saveuserinfo () {
Get the Accept return 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;
Receive the URL address for the form
var url = "commit.php tutorial";
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>
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.