0

我正在开发一个在线预订系统,所以我有一个 php 脚本,它接收一个日期并将输出一系列可能的时间段,这些时间段在该日期是免费的。我正在尝试这样做,以便在关闭日期选择器时将变量发送到文件并检索结果。目前提交按钮也指向 php 文件,并在我选择日期时显示可用的插槽。php 部分有效,但是当我向 datepicker 添加事件时,它不会向 php 文件提交任何变量。我认为这也是我添加另一个负载时的原因。('input_date.php'); 我得到了由 if(isset... 引起的完整时间段列表...谁能告诉我为什么 jQuery 会破坏我的变量发布?提前谢谢..

$(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>";
}

?>
4

1 回答 1

0

我相信这是因为你有这行代码:

$('#datepicker').serialize()

这应该更改为表单的 id 而不是数据选择器。在您的 PHP 中,您试图获得两个单独的值:

$treatment = $_POST['treatment'];
$bookdate = $_POST['bookdate'];

现在您只是发送输入字段#datepicker 的值。

于 2012-10-08T12:55:18.883 回答