Mailing List Archive


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

Re: [tlug] My first JSON object [SOLVED]



TLUG,

Okay, got it. It seemed that my sticking point was that when sending the JSON, I have to "stringify" it first.

I thought that since I was basically hand writing out my JSON in JSON syntax it was already in string form. As it turns out, though, it's gotta be stringified anyway.

Also, stripslashes() is necessary on the PHP side. Though I guess that depends on a server's magic quotes settings and whatnot. Works for me, anyway.

So, to get the JSON data to go to the server and then back again, here's how the code had to be written:

Javascript:

         var myData = {
            "name": "my_simple_object"
         };
         var myString = JSON.stringify(myData)
         $.post('jsonhandler.php', {myJSON: myString}, showResult, "json");

PHP:

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

I'm calling this thread solved because even though I'm now going to embark on actually, y'know, doin' stuff with the data I'm sending back and forth, which I'm sure will give me more headaches, the fundamental process of moving data back and forth seems to be working now.

Thanks to TLUG and all its members for the great support, both on list and off!

--
Dave M G


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links