我正在開發一個在線預訂系統,所以我有一個接收日期的php腳本,並將輸出當天可用的時隙數組。我試圖讓它在關閉日期選擇器時將變量發送到文件並檢索結果。目前提交按鈕也會導致php文件,並且在我選擇日期時會顯示可用的插槽。 php部分工作,但是當我添加事件到datepicker它不會提交任何變量的PHP文件。我認爲這也是當我添加另一個負載時的原因('input_date.php');我得到所造成的,如果(isset完整的時隙列表...誰能告訴我,爲什麼jQuery是毀了我的變量張貼在此先感謝..jQuery導致我的PHP中斷
$(document).ready(function() {
$("#dates").load('input_date.php');
$("#datepicker").datepicker({onClose: function() {
$.post("input_date.php", $('#datepicker').serialize());
alert(1);
}});
});
這是PHP文件:
<?php
include('connection.php');
error_reporting(0);
$treatment = $_POST['treatment'];
$bookdate = $_POST['bookdate'];
if(isset($treatment) && isset($bookdate)){
$exp = explode("-", $bookdate);
//determine what day of the week it is
$timestamp = mktime(0,0,0,$exp[1],$exp[0],$exp[2]);
$dw = date("w", $timestamp); // sun0,mon1,tue2,wed3,thur4,fri5,sat6
echo $dw."weekday"; //week day
echo"<br/>";
//find bookings with same date
$q = mysql_query("SELECT BOOK_SLOT_ID FROM BOOKINGS WHERE BOOK_DATE='$bookdate'");
//make array of booking slots
$array1 = array();
while ($s = mysql_fetch_array($q)) {
$array1[] = $s['BOOK_SLOT_ID'];
}
$q2 = mysql_query("SELECT SL_ID FROM SLOTS");
//make array of all slots
$array2 = array();
while ($s2 = mysql_fetch_array($q2)) {
$array2[] = $s2['SL_ID'];
}
//remove bookings from all slots
$arr_res = array_diff($array2, $array1);
//make selectable options of results
echo "<SELECT>";
foreach($arr_res as $op){
$r = mysql_query("SELECT SL_TIME FROM SLOTS WHERE SL_ID='$op'");
$q3 = mysql_fetch_array($r);
echo "<OPTION value=".$op.">".$q3['SL_TIME']."</OPTION>";
}
echo "</SELECT>";
}else{
$else = mysql_query("SELECT * FROM SLOTS");
echo "<SELECT>";
while($array_else = mysql_fetch_array($else)){
echo "<OPTION value=".$array_else['SL_ID'].">".$array_else['SL_TIME']."</OPTION>";
}
echo "</SELECT>";
}
?>
另外我有error_reporting(0);因爲我不想讓錯誤顯示在它加載到的第一頁上。使用error_reporting(E_ALL);說錯誤在第11行。當我回顯$ bookdate時,它沒有顯示它是空的。我想這個問題應該改寫爲什麼jQuery使提交的變量爲空或空? –