Hi,
I know this is probably going to be something that I missed. But I have been doing jQuery .post calls for a year now but can’t get this to work. Basically I’m sending and age to the server and checking what sports level it should be assigned to. Simple – No? NO! I can see from the headers that I am sending the JSON data to the server but when it gets there the $_POST call comes back as NULL.
Here’s the code
JavaScript:
function AgeInput(input) {
var data = "{ "age" : "+input.val()+" }";
$.post("ajax/getLevel.php", data, function(data) {
alert("Back from server with "+data);
});
}
getLevel.php
require_once(“../includes/dbConnect.php”);
ob_start();
$return_arr = array();
$age = $_POST;
$ageInt = intval($_POST);
$return_arr = $age;
$return_arr = $ageInt;
echo json_encode($return_arr);
?>
I’ve cut it down to try and find the issue.
My Header Post headings play out as:
Parametersapplication/x-www-form-urlencoded
{ "age" : 9 }
JSON
age 9
Source
{ "age" : 9 }
but my Header Response is
{"age1":null,"age2":0}
Anybody know why I am getting NULL for my $_POST call?? (Yeah, it’s probably something stupidly simple)
Thanks,
Kevin