输入JSON.parse(PHP、JSON、jQuery.post、数据库)意外结束
我有一个php文件,它创建json并将其传递给javascript输入JSON.parse(PHP、JSON、jQuery.post、数据库)意外结束,php,json,jquery-post,Php,Json,Jquery Post,我有一个php文件,它创建json并将其传递给javascript <?php $index = 0; $connection = mysql_connect(*secret*,*secret*,*secret*); mysql_select_db("sql7150348"); $query =mysql_query("SELECT * FROM statements"); while ($row = mysql_fetch_assoc($quer
<?php
$index = 0;
$connection = mysql_connect(*secret*,*secret*,*secret*);
mysql_select_db("sql7150348");
$query =mysql_query("SELECT * FROM statements");
while ($row = mysql_fetch_assoc($query)) {
$array[$index] = $row;
$index++;
}
echo json_encode($array);
但是我总是遇到这个错误(关于console.log(JSON.parse(data));
)
未捕获的语法错误:JSON输入意外结束在JSON.parse()
在Object.success(script.js:20)
在i(jquery.min.js:2)
在Object.fireWith[as resolveWith](jquery.min.js:2)
在A(jquery.min.js:4)
在XMLHttpRequest。(jquery.min.js:4)
我做错了什么导致出现此错误?客户端无法识别服务器接收到的响应类型。指定响应类型
JSON
应该可以解决这个问题
$.post('../php/getFromDatabase.php', function () {}).done(function (data) {
console.log(data);
}, "json");
您可以发布您的JSON字符串吗?您是否在浏览器控制台中从服务器获得JSON响应?JSON现在在post中,我如何检查JSON响应?您获得的是有效的JSON,因此无需解析它,直接在您的逻辑中尝试
数据
;
$.post('../php/getFromDatabase.php', function () {}).done(function (data) {
console.log(data);
}, "json");