SQL错误或PHP错误它在我的ajax [对象对象]中返回



当模态窗口中的按钮被单击时,正在调用 ajax。所以我得到了一个按钮,然后它会弹出一个带有是或否按钮的模态窗口,如果单击是,它将触发此 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");
?>

这是我的阿贾克斯

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);

最新更新