index.php
Code: Select all
httpRequest.onreadystatechange = function() { getResponse() };
httpRequest.open("GET", "PHPAPI.php?e=Hello Whats up", true);
httpRequest.send(null);
function getResponse()
{
if (httpRequest.readyState == 4)
{
if (httpRequest.status == 200)
{
alert(httpRequest.responseText);
}
else
{
alert('There was a problem with the request.');
}
}
}
Code: Select all
/************************************************
Javascript API.
************************************************/
(window.ActiveXObject) ? httpRequest = new ActiveXObject("Microsoft.XMLHTTP") : httpRequest = new XMLHttpRequest();
Code: Select all
<?php
echo $_GET['e'];
?>
Now what I'm really trying to get at in this post is: What is considered as a valid response form php? With this example using the echo keyword I can easily respond. But what other ways are there, if any? How would I return an Array as a response? Why, from my experience, does echo return a response? What exactly is going on here?
Answers to this are appreciated. I don't even know if I covered everything. But my sum is, what's responseText/responseXML properties expecting in a response? What makes one in php? Echo only?