单击模式窗口内的按钮时,将调用 ajax。所以我有一个按钮,然后它会弹出一个带有是或否按钮的模式窗口,如果单击是,它将触发这个 ajax 并将数据发送到我的 php.ini。它实际上在我的数据库中保存或更新我的表,但是当它返回时它在我的 ajax 中返回一个 [object object]。
这是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)
}
});