I. XMLHttpRequest
The Code is as follows:
<Script language = "javascript">
Function saveintroduce ()
{
// Obtain the accept response information layer
Var introducemsg = document. getElementById ("introducemsg ");
// Obtain the form object and user information value
Var f = document. introduceedt;
Var elm1 = encodeURIComponent (f. elm1.value );
// URL of the received form
Var url = "save. php? Id = <? = $ _ GET ["id"]?> ";
// The POST value. www. bKjia. c0m connects each variable through &.
Var postStr = 'elm1 = '+ elm1;
// Instantiate Ajax
// Var ajax = InitAjax ();
Var ajax = false;
// Start initializing the XMLHttpRequest object
If (window. XMLHttpRequest)
{// Mozilla Browser
Ajax = new XMLHttpRequest ();
If (ajax. overrideMimeType)
{// Set 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)
{
Introducemsg. innerHTML = ajax. responseText;
}
}
}
</Script>
<Form id = "introduceedt" name = "introduceedt" action = "save. php>" method = "post">
<Input name = "elm1" id = "elm1"> <input type = "button" value = "Submit Form" onClick = "saveintroduce () "> <div id =" introducemsg "> </div> </td>
</Form>
Ii. jquery ajax. post
1. jQuery $. post () method
The $. post () method sends an http post request to request data from the server.
Instance
The Code is as follows:
$ ("Button"). click (function (){
$. Post ("demo_test_post.asp ",
{
Name: "Donald Duck ",
City: "Duckburg"
},
Function (data, status ){
Alert ("Data:" + data + "Status:" + status );
});
});
2. Common Format of $. ajax
The Code is as follows:
$. Ajax ({
Type: 'post ',
Url: url,
Data: data,
Success: success,
DataType: dataType
});
2. $. ajax parameter description
Parameter description
The url is required. Specifies the URL to which the request is sent.
Data is optional. Ing or string value. Specifies the data sent to the server together with the request.
Success (data, textStatus, jqXHR) is optional. The callback function executed when the request is successful.
DataType is optional. Specifies the expected server response data type.
Intelligent judgment (xml, json, script, or html) is performed by default ).
For more details, see http://www.bKjia. c0m/wy/jquery/57064.htm