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>