使用php中的ajax检索数据

I have an ajax code which passes data to php and then retrieves data from php...

function updateDatabase(syncData){
    $.ajax({
            type : 'POST',
            async: false,
            url : 'php/syncData.php',
            dataType : 'json',
            data: {myData : syncData}, //i even used this "mydata"+syncData
            success : function(result){
                res = result;                               
            },
            error : function() {
                res = false;
            }
    });

    return res;
}

And here's my php code...

<?php

    include("database.php");

    if(isset($_GET['myData'])){
        $data = $_GET['myData'];

        $insert = "INSERT INTO `mydata` VALUES (NULL,'$data')";
        mysql_query($insert);


       $data = mysql_insert_id();
       echo json_encode($data);

}

?>

Here's javascript function that pass/calls ajax...

<script>

var theData = "blahblah";
var alertData = updateDatabase(theData);

alert(alertData);

</script>

the problem is that when i use htmt/text as data type it alerts empty/blank output, but when i used json as data type it alerts false where i conclude it went to error function not to success... anyone knows what's the proper way to do this? or maybe i'm just missing something? Thanks!

Well, you're posting the data using jQuery, but you're looking for a $_GET value in the PHP. Fix that and see if it changes anything.

Edit: It should look like this:

...
    if(isset($_POST['myData'])){
        $data = $_POST['myData'];
...

Try to set content type in your PHP file:

header( 'Content-Type: application/json' );

Then echo your data:

echo json_encode( $data );

Then exit script:

exit;

Hope it helps!