The following Ajax post values
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>
</Head>
<Script language = "JavaScript">
Function saveuserinfo ()
{
// Obtain the accept response information layer
VaR MSG = Document. getelementbyid ("MSG ");
// Obtain the form object and user information value
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 = "/ajax_output.php ";
// The post value is required to connect each variable through &
VaR poststr = "user_name =" + username + "& user_age =" + userage + "& user_sex =" + usersex;
// Instantiate Ajax
// Var Ajax = initajax ();
VaR Ajax = false;
// Start initializing the XMLHTTPRequest object
If (window. XMLHttpRequest) {// Mozilla Browser
Ajax = new XMLHttpRequest ();
If (Ajax. overridemimetype) {// sets the mime category
Ajax. overridemimetype ("text/XML ");
}
}
Else if (window. activexobject) {// IE browser
Try {
Ajax = new activexobject ("msxml2.xmlhttp ");
} Catch (e ){
Try {
Ajax = new activexobject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
If (! Ajax) {// exception. An error occurred while creating the object instance.
Window. Alert ("the XMLHTTPRequest object instance cannot be created .");
Return false;
}
// 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 );
// Obtain the execution status
Ajax. onreadystatechange = function (){
// If the execution status is successful, the returned information is written to the specified layer.
If (Ajax. readystate = 4 & Ajax. Status = 200 ){
MSG. innerhtml = Ajax. responsetext;
}
}
}
</SCRIPT>
<Body>
<Div id = "MSG"> </div>
<Form name = "user_info" method = "Post" Action = "">
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>
</Body>
The following is the Ajax get value
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>
</Head>
<Script language = "JavaScript">
Function saveuserinfo ()
{
// Obtain the accept response information layer
VaR MSG = Document. getelementbyid ("MSG ");
// Obtain the form object and user information value
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 = "/ajax_output.php? User_name = "+ username +" & user_age = "+ userage +" & user_sex = "+ usersex ";
// Instantiate Ajax
// Var Ajax = initajax ();
VaR Ajax = false;
// Start initializing the XMLHTTPRequest object
If (window. XMLHttpRequest) {// Mozilla Browser
Ajax = new XMLHttpRequest ();
If (Ajax. overridemimetype) {// sets the mime category
Ajax. overridemimetype ("text/XML ");
}
}
Else if (window. activexobject) {// IE browser
Try {
Ajax = new activexobject ("msxml2.xmlhttp ");
} Catch (e ){
Try {
Ajax = new activexobject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
If (! Ajax) {// exception. An error occurred while creating the object instance.
Window. Alert ("the XMLHTTPRequest object instance cannot be created .");
Return false;
}
// Open the connection through post
Ajax. Open ("get", URL, true );
// Send the get data, which has been assigned a value in the URL. Therefore, you only need to add an empty parameter to send the data.
Ajax. Send (null );
// Obtain the execution status
Ajax. onreadystatechange = function (){
// If the execution status is successful, the returned information is written to the specified layer.
If (Ajax. readystate = 4 & Ajax. Status = 200 ){
MSG. innerhtml = Ajax. responsetext;
}
}
}
</SCRIPT>
<Body>
<Div id = "MSG"> </div>
<Form name = "user_info" method = "Post" Action = "">
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>
</Body>