0
私はPHPのAjaxのリクエストを行うにしようとしていますが、私は、私はconsole.log
phpへのAjaxリクエストが失敗しましたか?
を持って成功部分を取得していないとして、失敗すると思われるいくつかの未知の理由のために、誰もが私に何をいくつかのヒントを与えてくださいすることができこれと一緒にwronかもしれない、私はあまりにも長い間立ち往生していますか?ここで
は私のjQueryがどのように見えるかです:
getPending();
function getPending(){
var usernameLS = localStorage.getItem('userNameLS');
var userTypeLS = localStorage.getItem('isAdminLS');
if (userTypeLS!=1) {
console.log("inside");//i am getting here
$.ajax({
type: "POST",
dataType: 'json',
url: 'get-pending.php',
data: {
data: usernameLS //this is a string, "user2" for instance
},
success: function(data) {
console.log("Thanks!!!",data);//i never got here
},
failure: function() {
console.log("Error!");
alert(' Fail');
}
});
}
そして、ここでは私のPHPです:あなたの出力は正しいJSON形式ではありませんように
<?php
$string = file_get_contents("appointments.json");
$usernameAjax = $_POST['data'];
var_dump($usernameAjax);
$json_a = json_decode($string, true);
$isPending;
foreach ($json_a as &$json_r) {
if ($usernameAjax==$json_r['userName'] && $json_r['status'] = "Pending") {
$isPending = 1;
}
else{
$isPending = 0;
}
}
var_dump($isPending);
echo $isPending; //i tried with a hardcodede 1 or 0 zero. Didn't work.
?>
は、障害機能(エラー)に追加してerror.messageをログに書かれた後に任意の出力を避けるために、代わりにエコー($出力)のダイ($出力)を使用することができます。 –
PHPファイルの最上部に 'error_reporting(E_ALL);'ステートメント – bodi0
エラーを記録しません。あなたはJSONをrequestiingが、JSON –