I am trying to read in a JSON message in my PHP app and this is my php code:
$json = file_get_contents(\'php://input\');
$obj = json_decode($json, TRUE);
ech
If you are using javascript to send JSON, to a php file
send_recieve.js
var myObject = JSON.stringify({"name":"John","age":30,"city":"New York"});
var xhr = new XMLHttpRequest();
xhr.open("POST","http://localhost/dashboard/iwplab/j-comp/receive_send.php",false);
xhr.setRequestHeader("Content-type","application/json");
xhr.onreadystatechange = function(){
if(xhr.readyState==4){console.log("xhr response:"+xhr.response)}
alert(xhr.responseText);
};
xhr.send(myObject);
recieve_send.php
echo statements work as a response.