【发布时间】:2021-08-06 17:23:42
【问题描述】:
我在 json 编码后从 php 页面获取 json。我正确地看到了我想要传递给 ajax 的页面中的 json。我发送的数据是通过 php 中的表单获取,保存在数组中,然后使用 json 编码传递。
但我从 ajax 得到错误对象:
我错过了什么?我也应该复制和粘贴我的后端的一部分吗?
$.ajax({
method: "GET",
url: "queries/queries.php",
dataType: "json",
succes: function(data){
console.log(data);
console.log('json found');
},
error: function(error){
console.log(error);
console.log('json not found');
}
});
后端:
$calls= "text";
for ($i=0;$i<count($array);$i++) {
$schemaTab = $array[$i] . $calls;
$query = "SELECT * from 'schema'.'table'"; // this is just a sample query
$res=$db->getQuery($query); // this is a function that output the db query
header('Content-Type: application/json');
echo json_encode($res); // the json i pass
}
json:
[{"Schema":"schemaName1","DATEHOUR":"10\/05\/2021 11:56","count":"4"}]
[{"Schema":"schemaName2","DATEHOUR":"10\/05\/2021 10:21","count":"3"}]
[{"Schema":"schemaName3","DATEHOUR":null,"count":"0"}]
[{"Schema":"schemaName4","DATEHOUR":null,"count":"0"}]
【问题讨论】:
-
分享其中的php代码和示例json。有助于更快地解决问题。
-
我看到 statusCode 200 a text="OK",这不是错误消息。在您的代码中,我只看到一个错字,
succes与success。 -
您没有在请求中发送任何
data,succes必须是success。投票结束,因为问题是由拼写错误引起的。 -
我更正了成功的错字,但仍然没有得到数据。我正在复制并粘贴 backedn 等待 2 分钟。谢谢。
-
错误是什么?