そのため、一部のコンピューターではすべてが正常に機能します。私は自分のラップトップ> firefox>自分のウェブサイトにアクセスします。いいえ、ajax リクエストはエラー '[object Object]' を返しています。Chrome と IE に入ります...JSON 文字列は、アラートで "joe is the man from: JSON" を返します。Jquery に JSON を処理する既知の問題があるかどうかを知る必要がありますか? 私の携帯電話のクロムがエラー「[object Object]」を返すことを考えると、このランダムな問題に遭遇する人が私のページにアクセスすることはできません.
<?php
//------------------------------The php file sending JSON
$results = array(
"price" => "joe is the man from: JSON",
);
print(json_encode($results));
?>
<script>
$.ajax({
url: "myphpfile.php",
dataType: "json",
success: function(data){
alert(data.price);
},
error: function(error){
alert(error);
}
});
}
</script>
念のため、これをPHPファイルに追加しようとしました....同じ結果:
header('Content-type: application/json');
わかりましたので、これに変更します:
$.ajax({
url: "myphpfile.php",
dataType: "json",
success: function(data){
alert(data.price);
},
error: function(xhr, status, error) {
alert(status);
alert(xhr.responseText);
alert(xhr);
}
});
alert(status) - 「エラー」を返しました alert(xhr.responseText); - 空白のボックス アラート (xhr) を返しました。- '[オブジェクト オブジェクト]' を返しました
編集:これはすべてのブラウザで動作しなくなりました....