I know this seems way too complicated to be the case, but I'm baffled.
I have a page using jQuery's post method to send an AJAX POST request to my API. They are both on the same domain/server.
$.post('api/login.php', {username: 'test', password: 'test'}).done(function (res) {
alert(res.response);
});
The API looks like this:
<?php
exit (json_encode(array ('response' => print_r($_REQUEST, true))));
This works as expected in my local WAMP setup, but on Bluehost, it shows simply Array ()
as if there were no parameters in the request.
If I change $.post
to $.get
, it receives both parameters just fine.
It also works as expected if I use an HTML form and send the data without using AJAX, e.g.
<form method="post" action="api/login.php">
<input type="text" name="username" value="test">
<input type="text" name="password" value="test">
<input type="submit">
</form>
I think I've exhausted the tests I can create to try to eliminate any other possibility, and it just is coming down to something really strange -- my PHP script doesn't receive POST fields in an AJAX request.