gpt4 book ai didi

php - SQL 错误或 PHP 错误在我的 ajax [object object] 中返回

转载 作者:行者123 更新时间:2023-11-29 08:46:03 25 4
gpt4 key购买 nike

当模式窗口内的按钮被点击时,ajax被调用。所以我有一个按钮,然后它会弹出一个带有"is"或“否”按钮的模式窗口,如果单击"is",它将触发此ajax并将数据发送到我的php。它实际上在我的数据库中保存或更新我的表,但当它返回时,它在我的ajax中返回一个[对象对象]。

这里是php

// get data
$selGuest = $_POST["selGuest"];

include("openDB.php");

//3.) insert a record

$insertintoCanceled = "insert into tbl_canceled "
."(reserved_id, guest_id, checkin, checkout, type_id, numAdults, numChildren, transacstatus, amountDue)"
."("
."SELECT * FROM tbl_bookings where reserved_id = " .$selGuest
.")";
if(!mysql_query($insertintoCanceled, $con))//if it fails
{
echo json_encode(array('msg'=>'Error')) //error msg goes here
die('Error: ' . mysql_error() . "\n");//show the mysql error

}
echo json_encode(array('msg'=>'Successfully updated')) //success msg goes here



include("closeDB.php");
?>

这是我的ajax

var canceldata_json = {
'selGuest': selGuest,
};
$.ajax({
type: "POST",
data: canceldata_json,
dataType:'json',
url: "./php/cancelBooking.php",
success: function(msg) {
alert("guest information updated real")
$('#confirmDialog').fadeOut('slow');

},
error:function(msg){
alert(msg)
}
});

最佳答案

它正在解析您返回的 JSON。改为这样做:

alert(msg.msg);

关于php - SQL 错误或 PHP 错误在我的 ajax [object object] 中返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12516602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com