Ajax发布空数据

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:

    jQuery.ajax({
        url:'/api/registerLoginViaFacebook.php',
        data: {'test1':'test1','test2':'test2'},
        type:'POST',
        success: function(result) {
            jQuery('header').html(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 registerLoginViaFacebook.php file:

<?php

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

?>

the html thats getting inserted in the <header> is

hey

null

suggesting that the data i specified was never sent - at least that's what I make of it. I tried including $_REQUEST['data']; at the start of the file as per some suggestions I found on here but still no joy. Where have I gone wrong?

On the PHP end, try using $_POST['test1'] and $_POST['test2']. This should contain the data you sent via jQuery.

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

$data = $_POST;