H3X
01-03-2011, 06:44 AM
Hey, I am looking for an Ajax function that returns the contents of the page. I have been trying to use this:
function xmlhttpPost(strURL, cword) {
var xmlHttpReq = false;
var self = this;
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
return self.xmlHttpReq.responseText;
}
}
self.xmlHttpReq.send('q='+cword);
}
But, do you see on the 5th line up how I try to return the contents? This is obviously not going to work because the return is in another function.
So, basically, I just need a simple function that has POST capabilities, and returns the contents of the page. I have been trying to do this myself for the last hour or so with no luck. I also have been searching around quite a bit but can't find much.
Does anyone have one they could share, or could someone make the necessary adjustments to mine?
Thanks!
function xmlhttpPost(strURL, cword) {
var xmlHttpReq = false;
var self = this;
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
return self.xmlHttpReq.responseText;
}
}
self.xmlHttpReq.send('q='+cword);
}
But, do you see on the 5th line up how I try to return the contents? This is obviously not going to work because the return is in another function.
So, basically, I just need a simple function that has POST capabilities, and returns the contents of the page. I have been trying to do this myself for the last hour or so with no luck. I also have been searching around quite a bit but can't find much.
Does anyone have one they could share, or could someone make the necessary adjustments to mine?
Thanks!