Ajax by POST

function postbyAjax(frmobj) {

url = “send-request.php?”;

var frmobjarglist = frmobj.elements;

var frmobjarglistlen = frmobj.elements.length;

var poststr = “”;

for(i=0;i<frmobjarglistlen;i++) {

poststr += frmobjarglist[i].name+”=”+frmobjarglist[i].value+”&”;

}

poststr = poststr.substring(0,(poststr.length-1));

var req = null;

try { req = new ActiveXObject(“Msxml2.XMLHTTP”); }

catch(e) {

try { req = new ActiveXObject(“Microsoft.XMLHTTP”); }

catch(oc) { req = null; }

}

if (!req && typeof XMLHttpRequest != “undefined”) { req = new XMLHttpRequest(); }

if (req != null) {

req.open(“POST”, url, true);

req.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”);

req.setRequestHeader(“Content-length”, poststr.length);

req.setRequestHeader(“Connection”, “close”);

//Send the proper header information along with the request

var returnresult=””;

req.onreadystatechange = function() {//Call a function when the state changes.

if (req.readyState == 4 && req.status == 200) {

if (req.responseText!=””) {

returnresult = req.responseText;

} else{

returnresult= “”;

return false;

}

if(Trim(returnresult)==”submitted”) {

frmobj.submit();

}

} else {

returnresult=””;

}

}

req.send(poststr);

}

}

About selvam4win

I am Selvam. I am very jolly person and frank one.

Posted on July 31, 2010, in Ajax, Ajax POST, javascript and tagged , , , . Bookmark the permalink. Leave a comment.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: