Benjamin Liger Benjamin Liger - 9 months ago 48
jQuery Question

Ajax posting null data

I'm trying to echo a php variable from an Ajax request but the data is being returned as "null" and im not sure why. Here is my post request:

data: {'test1':'test1','test2':'test2'},
success: function(result) {

The data i'm posting here is just test data. As i'm having the same problem posting the real data. Here is the


echo "<p>hey</p>";
echo "<p>".json_encode($data)."</p>";


the html thats getting inserted in the
is heynull suggesting that the data i specified was never sent - at least that's what I make of it. I tried including
at the start of the file as per some suggestions I found on here but still no joy. Where have I gone wrong?

Answer Source

You need to set $data in your PHP script. Since you are sending the information via POST you can do this:

$data = $_POST;