I can't for the life of me figure out what I'm doing wrong. It seems like it should be simple because I can't find anyone else with this issue but I can't figure out to send basic data via javascript(jQuery) to PHP and decode it. For the sake of simplicity, this is what I have:
JAVASCRIPT
var json_data = { "name" : "john doe" };
$.ajax({
type: "POST",
url: "../bin/process.php",
dataType: "json",
data: json_data
});
and my PHP FILE
$arr = json_decode("json_data", true);
$fp = fopen('data.txt', "w");
fwrite($fp, $arr['name']);
fclose($fp);
The file I'm writing ends up with nothing in it. If I do an:
fwrite($fp, 'test');
I get a file with the word test in it but no matter what I do I don't get the json data I sent.
Can someone please share a thorough example of A to Z. Thanks for any help.