0
我正在从JS文件到另一个文件中的PHP函数的Ajax调用。虽然Ajax调用成功,但它保存了记录,但我没有找回正确的数据进行处理。相反,我从页面获取html。我需要能够检查状态,以便如果成功就可以继续前进,或者通知用户是否有任何类型的错误未保存记录。这是我的JS代码。为什么我的JSON不能正确地从PHP返回?
$.ajax({
type: "POST",
url: "utils.php?do=saveTick",
data: {'dtData': JSON.stringify(sendData)},
success: function (data) {
alert(data.status);
if (data.status != "SUCCESS") {
$("#updateDiv").dialog('destroy');
alert("Failed!");
$("#btnPrint").attr('disabled', false);
return false;
} else {
me.confirmSave();
}
}
}, 'json'
);
并通过PHP处理后,这是我试图返回我的JSON,所以我可以检查它。在我的try/catch我有这个
try {
$data = json_decode($_REQUEST['dtData']);
$values = $data[0];
$ordNbr = $values->ordnbr;
$saveTick = Do something and save the ticket
// if ($saveTick->status === "SUCCESS") {
$this->getSalesData($values, $ordNbr);
echo json_encode($saveTick);
} catch (Exception $e) {
$saveTick = array('status' => 'FAILED');
echo json_encode($saveTick);
}
而这就是返回到控制台从我的console.log上述
<html>
<head>
<title></title>
<style>
TR.main_header {
background-color:black;
color:white;
}
TR.main_footer {
background-color:#396B42;
color:white;
}
div.error {
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr class="main_header">
<td align="left" width="25%"></td>
<td align="right" width="25%">Tuesday May 31,2016</td>
</tr>
</table>
[{"shipdate":"2016-05-31","ordnbr":"BR549","custid":"CUST","deltcktno":"D333423","siteid":"Some Site","dttype":"REG","IsExport":true,"slsperid":"","slsname":"Some Sales","slsemail":"[email protected]"}]{"status":"SUCCESS","message":"Successfully called","data":null,"count":0}
</body>
</html>
所以,你的php文件包含一些header.php或一些统计数据。 –
这是*期望*。确保你没有在生成JSON的文件中包含任何东西 –
上面有什么'console.log'? – Barmar