sonicsshadow
Member
- Messages
- 200
- Reaction score
- 0
- Points
- 16
Hi, I'm trying to make it so that AJAX will return a value to javascript rather than just printing out stuff. Is this possible?
I don't think you'd be able to do something like:Hi, I'm trying to make it so that AJAX will return a value to javascript rather than just printing out stuff. Is this possible?
return "Test"
I don't think you'd be able to do something like:
for AJAX. You have to echo/print what you want to return.PHP:return "Test"
if ($_REQUEST['ajax']=="getValue") {echo $value;exit;}
//xmlHttp = new ajax object (browser specific code/try catch here)
xmlHttp.onreadystatechange=function() {
if(xmlHttp.readyState==4) {
if (xmlHttp.status==200) {
doSomethingWithThisValue(xmlHttp.responseText);
}
}
}
//send the request
xmlHttp.open("POST", "http://www.thispage.php", true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send("ajax=getValue");