AJAX – POST request

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


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”);


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) };

Ajax Basics – https://manikandanmv.wordpress.com/2008/09/23/ajax-asynchronous-javascript-and-xml/
Ajax GET request – https://manikandanmv.wordpress.com/2008/09/29/ajax-example/

Tags: , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: