Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] My first JSON object



TLUG,

Whoops, noticed a small copy and paste error in my code.

Ignore what I had earlier. This is the code I'm using, which isn't working.

Javascript:

var myJSON = { "name": "my_simple_object" };
$.post('jsonhandler.php', myJSON, showResult, "text");
function showResult(json_data_received)
{
    console.log("The value of the JSON object is: " +
JSON.parse(json_data_received));
}

And here's my PHP:

$data = json_decode(stripslashes($_POST['myJSON']));
Header("Content-Type: application/json");
echo json_encode($data);

Just to be clear. The goal is to send JSON data to the PHP script which should just turn around and send it right back. However, the response I'm getting from the server is "null".

Any idea where I'm going wrong?

Any advice or suggestions much appreciated.

--
Dave M G



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links