Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Can’t get $_POST data from jQuery $.post calls

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #37292
    kam
    Member

    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

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.