有人可以帮忙吗?这是我的 jQuery。场景是这样的,我有一个表格,其中每个按钮都有一个按钮<td>
。如果单击该按钮,将出现一个模态窗口,上面有一个确认按钮,是或否。如果用户单击是 ( #confirm_cancel
),这将保存在数据库中,然后显示一个警告框,告诉用户更新成功。问题是这样的,它正确执行了我的 SQL 并保存到数据库中,但我在错误函数上收到一个警告框,上面写着[object object]
.
这是我的PHP:
<?php
include("php/openDB.php");
echo '<table border="2" id="tableGuestList">';
echo '<tr>';
echo '<td>Guest ID</td>';
echo '<td>Room No:</td>';
echo '<td>First Name</td>';
echo '<td>Last Name</td>';
echo '<td>Checkin</td> ';
echo '<td>checkout</td>';
echo '<td>Status</td>';
echo '</tr>';
$result = mysql_query("SELECT gi.guest_id, gi.fname, gi.lname, bk.checkin, bk.checkout, bk.transacstatus, bk.reserved_id "
."FROM tbl_guestinfo gi, tbl_bookings bk "
."where gi.guest_id = bk.guest_id "
."AND bk.transacstatus = 'booked'");
while ($rows = mysql_fetch_array($result, MYSQL_NUM)) {
$guest_id = $rows[0];
$fname = $rows[1];
$lname = $rows[2];
$checkin = $rows[3];
$checkout = $rows[4];
$transacstatus = $rows[5];
$reservedid = $rows[6];
echo '<tr id="'.$rows[0].'" class="bookedClass">';
echo '<td>'.$guest_id.'</td>';
echo '<td> room number kaara</td>';
echo '<td> '.$fname.'</td>';
echo '<td>'.$lname.'</td>';
echo '<td> '.$checkin.'</td>';
echo '<td>'.$checkout.'</td>';
echo '<td> '.$transacstatus.'</td>';
echo '<td style="display:none"> '.$reservedid.'</td>';
echo '<td> <input type = "submit" value = "Cancel Booking" name ="cancel_booking" /></td>';
echo '<td> <input type = "submit" value = "Check in" name ="check_in" /></td>';
//echo '<td> <input type = "submit" value = "Check Out" name ="Check_Out" /></td>';
echo '</tr>';
}
mysql_free_result($result);
echo '</table>';
include("php/closeDB.php");
?>
这是我的jQuery
$(document).ready(function(){
var selGuest;
$('#tableGuestList .bookedClass').click(function(){
selGuest = $(this).find("td").eq(7).text();
selGuest = parseInt(selGuest)
$('#confirmDialog').fadeIn('slow');
});
$('#confirm_cancel').click(function() {
var canceldata_json = {
'selGuest': selGuest,
};
$.ajax({
type: "POST",
data: canceldata_json,
url: "./php/cancelBooking.php",
success: function(msg) {
alert("guest information updated")
$('#confirmDialog').fadeOut('slow');
},
error: function(msg){
alert(msg)
}
});
});
$('#cancel_cancel').click(function() {
$('#confirmDialog').fadeOut('slow');
});
});
这是我的 PHP 代码被 AJAX 调用
<?php
// get data
$selGuest = $_POST["selGuest"];
include("openDB.php");
$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
{
die('Error: ' . mysql_error() . "\n");//show the mysql error
}
include("closeDB.php");
?>