Learn Ajax tutorials and learn more about get and post
GetMethod:
Function: Transfers simple data.
Size: The maximum URL length is 2083 bytes. The length of data transmitted by get is 2048 bytes.
Body: append data to the URL for sending, that is, HTTP header Transfer
PostMethod:
Function: Transfers simple and complex data.
Size: Limited in Web. config
Body: data is transmitted in the object content of the HTTP request.
Ajax transmits data in post mode. Note the following:
1. Set the context-type of the header to application/X-WWW-form-urlencode to ensure that the server knows that there are parameter variables in the object.
SetRequestHeader ("Context-Type", "application/x-www-form-urlencoded ;")
2. The parameters are key-value pairs with one-to-one names and values separated by an ampersand (&). For example, name = ABC & sex = Man & age = 18.
3. the parameter is sent in the send (parameter) method.
4. server Request Parameters are differentiated between get and post. for example, in Asp.net, request. form ["name"] Request Parameters in the object. in this case, the URL parameter request is. querystring ["name"] will cause an exception
<JavaScript type = "text/JavaScript" Language = "JavaScript">
Function createxmlhttp ()
{
If (window. activexobject)
{
Return new activexobject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest)
{
Return new XmlHttpRequest ();
}
}
// Configure //---------------------------------------------------------------------------------------------------------------------
// Post method:
Function Start ()
{
Var ParamString = "name = abc & sex = man & age = 18 ";
Var XmlHttpObject = CreateXmlHttp ();
XmlHttpObject. onreadystatechange = StateEvent;
XmlHttpObject. open ("post", "test. aspx", true );
XmlHttpObject. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded;"); // sets the Server Response Request body parameters
XmlHttpObject. send (ParamString );
}
// Configure //---------------------------------------------------------------------------------------------------------------------
// Get method:
Function Start ()
{
Var XmlHttpObject = CreateXmlHttp ();
XmlHttpObject. onreadystatechange = StateEvent;
XmlHttpObject. open ("get", url, true );
XmlHttpObject. send (null );
}
// Configure //---------------------------------------------------------------------------------------------------------------------
// Create a callback function
Function StateEvent ()
{
If (http_request.readyState = 4) // server response status
{
If (http_request.status = 200 | http_request.status = 304) // code execution status
{
Var resStr = http_request.responseText;
Alert (resStr); // process the business logic here
}
Else
{
Alert ("the page you requested has an exception! ");
}
}
Else
{
SelectedResTits. innerHTML = " ";
}
}
</Script>