I'm just getting into AJAX and I've figured out generally how to work with it and the GET method, but being the paranoid person I am, I want to try and get the POST method working as well. I haven't been able to figure it out though, here is my code:
var http = createRequestObject();
function sndReq(action) {
http.open('post', 'rpc.php');
http.onreadystatechange = handleResponse;
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.send(action);
}
It's sending a variable to the next page with a parameter name of 'POST_DATA' and the correct value (action = foo) but I can't seem to interpret the variable correctly on the next page. I would also like to figure out how to name the paramater name something other than 'POST_DATA' if possible. Here is my last try at getting the results:
<?
switch($_POST['POST_DATA']) {
case 'foo':
echo "foo|foo moot";
break;
case 'foo2':
echo "foo|foo2 yeah";
break;
case 'foo3':
echo "foo|foo3 woot";
break;
default:
echo "foo|foo4 default";
break;
}
?>
It only catches on the default (which I have just put in). I have 3 links which pass in the different variables which I can get to work with GET or REQUEST but the name for the post data eludes me. Looks like this should be the last pointer I need, suggestions?