在以下示例中,我需要知道如何通过 json 调用读取 MySql 表的 php 脚本,并返回带有要禁用的 $myBadDates 的数组:
$(function() {
$( "#pickdate" ).datepicker({
dateFormat: 'dd MM yy',
beforeShowDay: checkAvailability
});
})
var $myBadDates = new Array("10 October 2010","21 October 2010","12 November 2010");
function checkAvailability(mydate){
var $return=true;
var $returnclass ="available";
$checkdate = $.datepicker.formatDate('dd MM yy', mydate);
for(var i = 0; i < $myBadDates.length; i++)
{
if($myBadDates[i] == $checkdate)
{
$return = false;
$returnclass= "unavailable";
}
}
return [$return,$returnclass];
}
这是我的 php 脚本:close_dates.php,我如何发送 json ajax 请求并将数组结果获取到 checkAvailability 函数中:
>
include 'panel/db.php';
$dates_closed = array();
/// Query Dates Closed ///
$query = "SELECT dates from closed_dates order by dates ";
$result = mysql_query($query);
while($row=mysql_fetch_array($result)) {
$days = $row['dates'];
array_push($date_closed,$days);
}
echo json_encode($date_closed);
?>