Ajax – GET & POST

// Ajax By POST method
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;
}
display_result(returnresult); // Perform after ajax call
} else {
returnresult=””;
}
}
req.send(poststr);
}
}

// Ajax By GET Method
var contactobj = “”;
function getContacts(textobj) {
//url = “http://192.168.0.15/centerpoint/index.php?option=com_contactinfo&format=raw&typedtext=”+typedtext;
contactobj = textobj;
url = “http://192.168.0.15/selvam/content.php?typedtext=”+textobj.value;

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) {
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;
}
// Perform after ajax call
document.getElementById(“div_contacts”).innerHTML = returnresult;
document.getElementById(“div_contacts”).style.display = ”;
document.getElementById(“txt_test”).focus();
} else {
returnresult=””;
}
}
req.open(“GET”, url, true);
req.send(null);
}
}
function pouplateval(resulttext) {
contactobj.value = resulttext;
document.getElementById(“div_contacts”).style.display = ‘none’;
}

About selvam4win

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

Posted on August 27, 2010, in Ajax, Ajax POST, javascript, Uncategorized. 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: