I am getting a string from file_get_contents('php://input')
. I tried json_decode()
, but the string is not a json. Here is the ajax request and the php code. How can I get the json sent from the ajax request and turn it into a php array?
$data = file_get_contents('php://input');
var_dump($data);
echo $data;
Output:
string(7) "id=myId"
"id=myId"
Ajax(Includes Jquery):
$.ajax({
"url": "myFile.php",
"type": "POST",
"contentType": "Json",
"data": {"id": "myId"},
}).done(function(data, status) {
if (status == "success") {
console.log(data);
}
}).fail(function(data, status, error) {
throw new Error(error);
console.log(data);
console.log(status);
});
Edit: json_encode()
is returning null, so I cannot use the answer from this question: PHP: file_get_contents('php://input') returning string for JSON message