json配列をajaxから取得しようとしましたが、テキストファイルに書き込むときに何も表示されません。PHPはAJAX JSONデータを取得しません
var img = JSON.parse(localStorage.getItem("iPath"));
var img = JSON.stringify(img);
console.log(img);
$.ajax({
url: './php/temporary.php?deletefile',
cache: false,
type: 'POST',
data: img,
success: function(respond, textStatus, jqXHR){
if(typeof respond.error === 'undefined'){
//window.location.assign("/buyplace.html");
}
else{
console.log('ОШИБКИ ОТВЕТА сервера: ' + respond.error);
}
},
error: function(jqXHR, textStatus, errorThrown){
console.log('ОШИБКИ AJAX запроса: ' + textStatus);
}
});
if(isset($_GET['deletefile'])){
$params = json_decode($_POST);
$myfile = fopen("testfile.txt", "w");
fwrite($myfile, $params);
//$img = "uploads/" . $imgPath;
//move_uploaded_file($imgPath, "./uploads/");
//unlink('./uploads/' . $img);
}
?>
どうすればこの問題を解決できますか?
。また、あなたのajax呼び出しのdeletefileは空になり、設定もされていないので、.phpを変更してみてくださいdeletefile = true – dsadnick
'$ jsondata = json_decode(file_get_contents( 'php:// input'))' – Scuzzy
... $ _GET ['deletefile'] 'はURL行にあるので、まだ入力されていなければなりません。 – Scuzzy