POST Json string into a php page

You must Login before you can answer or comment on any questions.

I have a json object and i want to post that object to a php page. i have written a code but its not working can anyone help me to do this. my sample code is var xhr = Titanium.Network.createHTTPClient();

    var postData = {
        'object': { 'x':'value1','y':'value2' }
};

xhrPost.open('POST','http://localhost/TestDB/insert.php');
   xhrPost.send(JSON.stringify(postData));

I don;t know whether the above syntax is correct. Also i don't know how to get it inside my server page. Please help.Thanks

2 Answers

var xhr = Titanium.Network.createHTTPClient();
    var postData = {
        'object': { 'x':'value1','y':'value2' }
};
 
xhrPost.open('POST','http://localhost/TestDB/insert.php');
   xhrPost.send({'postdata':JSON.stringify(postData)});
and then in PHP:
<?php
print_r(json_decode($_POST['postdata'])); //the result will be sent to titanium, you can also store it in a database or something.
?>

Your Answer

Think you can help? Login to answer this question!