I am attempting to write a Json file to the server. The Object is created in Javascript and passed to PHP via Ajax. PHP will then write the data to a file on the server.
The problem I am having is Passing the object to PHP. Creating the Object is OK, as is writing to a file.
I have tried a wide variety of methods to pass the object (Post, Get, urlencoded, not urlencoded, stringified or not), but the PHP either gets "[object,object]" or nothing at all.
var testData = [{"name": "Foo"},{"name": "Bar"}];
$.ajax({
url : "include/WriteFile.php?json",
type : 'post',
data : JSON.stringify(testData),
dataType : 'application/json',
processData : false
});
-- WriteFile.php
<?php
$json = $_GET['json'];
$jsonData = json_decode($json,false);
// echo $jsonData;
$myFile = "../myFile.json";
$file = fopen($myFile, 'w') or die("can't open file");
fwrite($file, $jsonData); // Write file
fclose($file);
?>
--
// Header Info //
Parameters application/x-www-form-urlencoded
[{"name":"Foo"},{"name":"...
Source
%5B%7B%22name%22%3A%22Foo%22%7D%2C%7B%22name%22%3A%22Bar%22%7D%5D
xdebug is showing that both $_GET and $_RESPONSE are empty (Value = "").
Any help will be greatly appreciated.