If you want to send data with large size (GET allows up to 255 characters only). you can use POST method.
Mostly, POST methods are used in HTML forms. Let see the syntax of open & send method.
open(param1, param2, param3);
param1 – specifies HTTP request method (GET, POST, HEAD, etc..,)
param2 – action url, the page you are requesting.
param3 – specifies an asynchronous request if its true
send(params);
params - passing parameters of the POST request, in the form of query string.
Note : this parameter has null value when you send a request as GET method.thats the only difference.
Set the below MIME type for any POST requests made via Ajax.
setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”);
The below two lines are optional. If you want you can specify it.
setRequestHeader(“Content-length”, params.length);
setRequestHeader(“Connection”, “close”);
Example
sendAjaxRequest(“projectdetails.jsp”, “projectid=1024&module=accounts”, “showdetails”);
function sendAjaxRequest(url, params, divid)
{
url = url + getNoCacheValue(url);
var req = getXMLHttpRequest();
req.open(‘POST’, url, true);
req.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”);
req.setRequestHeader(“Content-length”, params.length);
req.setRequestHeader(“Connection”, “close”);
req.onreadystatechange = function(){ processResponseHTML(req, divid) };
req.send(params);
}
Ajax Basics – http://manikandanmv.wordpress.com/2008/09/23/ajax-asynchronous-javascript-and-xml/
Ajax GET request – http://manikandanmv.wordpress.com/2008/09/29/ajax-example/
Tags: AJAX, ajax basics, ajax example, ajax GET request, AJAX POST MIME type, AJAX POST request, XMLHttpRequest