So I have here a fresh installation of openSUSE, with Apache2, PHP5 and all the necessary whozits as one would expect. Thing is, I’ve run into a very strange bug. My $_POST isn’t being populated through ajax posts.
<?php
if (!empty($_POST)) {
print_r($_POST);
die;
}
?>
<html>
<body>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function postWithAjax() {
$.post("test.php", {
sentBy: "ajax",
});
}
</script>
<form name="input" action="test.php" method="post">
<input type="hidden" name="sentBy" value="formSubmit">
<input type="submit" value="Ajax Post" onclick='postWithAjax(); return false;'>
<input type="submit" value="Form Submit" onclick='testpost();'>
</form>
</body>
</html>
When I do a regular form submit, $_POST is populated as we’d expect, but the ajax post responds with the whole HTML as $_POST is empty. Empty? It shouldn’t be empty; I just posted a variable.
I’m stumped. Is this something strange with my Apache/PHP settings that I’m supposed to adjust to allow ajax posts? Nothing’s been altered. It’s all out-of-the-box config.