我正在使用JSON post请求从mySQL数据库返回行。我的服务器端语言是php,除非我将sql中的结果限制为大约45,否则我没有得到回复。没有错误只是没有回应。任何意见,将不胜感激。 服务器端代码如下;
<?php
include('../config.php');
$status = $_POST['status'];
$itemGrp = $_POST['itemGrp'];
$jobs_sql = "SELECT custName
,SODocNum
,itemName
,cast(thickness as decimal (4,2)) as 'thickness'
,case when ca_Description like 'Diary%' then ca_Description else 'Bespoke Diary' end as ca_Description
,Quantity
,version_id
,case when T0.rqdByDate is null then '' else T0.rqdByDate end as rqdByDate
,T0.despatchDate
,case when T0.versionStatus = 010 then '' else 'w3-disabled' end as 'disableCmpltBtn'
,case when T0.versionStatus = 010 then 'update_status_complete' else '' end as 'noclickCmpltBtn'
,case when T0.versionStatus = 009 then '' else 'w3-disabled' end as 'disableChkBtn'
,case when T0.versionStatus = 009 then 'update_status' else '' end as 'noclickChkBtn'
FROM Versions T0 left outer join components_all T1 on T0.itemCode = T1.ca_versionCFG and T1.ca_itemGroup in (117,118)
WHERE versionStatus in ('$status')
and ItmsGrpCod in ('$itemGrp')
order by thickness, T1.ca_itemCode asc, T0.despatchDate asc, SoDocNum
LIMIT 45";
$jobs_result = mysqli_query($db,$jobs_sql);
$all_array = mysqli_fetch_all($jobs_result);
echo json_encode($all_array);
?>
这就是我在客户端的所有内容;
function get_jobs_to_bind(){
console.log("Request data from server");
$.post("/_api/jobs_to_bind_api.php",
{
status:'007',
itemGrp:'121\',\'104\',\'106'
},
function(data) //on recieve of reply
{
console.log("Build table with data")
$('#jobs_to_bind_table_body').empty();
$.each(data, function (index, item) {
var eachrow = "<tr>"
+ "<td>" + item[0] + "</td>"
+ "<td style='text-align:center'>" + item[1] + "</td>"
+ "<td>" + item[2] + "</td>"
+ "<td>" + item[3] + "</td>"
+ "<td>" + item[4] + "</td>"
+ "<td>" + item[7] + "</td>"
+ "<td>" + item[8] + "</td>"
+ "<td>" + item[5] + "</td>"
+ "<td><button class='w3-btn w3-round w3-green w3-tiny' value = '" + item[6] + "' onclick='update_status(\"008\","+ item[6] +")'>Gathered</button></td>"
+ "<td><button id='viewgathererinfo' class='w3-btn w3-round w3-green w3-tiny' value = '" + item[6] + "' onclick='getgathererinfo("+ item[6] +")'>View</button></td>"
+ "</tr>";
$('#jobs_to_bind_table_body').append(eachrow);
});
filterbind2();
filterbind3();
},'json');
}
答案 0 :(得分:0)
实际发生的事情是我们得到了回复,但这是一个空洞的回应。 SQL没问题,可以在MySQL工作台上运行。我在php中发现了以下函数,它将显示json_encode中的任何错误; echo json_last_error_msg();
这显示以下错误; “格式错误的UTF-8字符,可能编码错误”
这是一个巨大的帮助!并解释了为什么尺寸不影响我们是否得到了结果以及为什么限制结果。显然有一行带有json_encode不喜欢的字符。我在MySQL工作台中找到了这一行,我认为这是一个导致问题的冒号。通过在服务器端代码中包含一行来将char设置为utf8来解决问题。
mysqli_set_charset($db,"UTF8");
其中$ db是我的数据库连接信息