モーダル ウィンドウ内のボタンをクリックすると、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");
?>
そして、ここに私の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)
}
});