【发布时间】:2014-08-05 12:47:33
【问题描述】:
我正在制作 CakePHP 应用程序,目前我正在编写脚本来发出 ajax 请求以突出显示 jQuery datePicker 的保留日期,并且 onSelect 使用 jQuery Accordion 发出另一个 Ajax 请求以显示有关特定日期的预订信息。
但是,我的日历没有显示,并且在 Firebug 控制台中出现错误 - “类型错误:O 未定义。函数 i(t, i){ 在 jquery-ui.custom.min.js 文件中”。在实施某些日子的亮点之前,脚本运行良好。
查看(日历.ctp):
<?php
$this->set('title_for_layout', __('Calendar'));
$this->Html->css('jquery-ui.custom', null, array('inline' => false));
$this->Html->script('jquery-ui.custom.min', array('inline' => false));
?>
<div class="row">
<div class="span3" id="datepicker"></div>
<div class="span7" id="hours"></div>
</div>
我的脚本:
$(document).ready(function() {
$.ajax({
url: '<?php echo Router::url(array('controller' => 'streservations', 'action' => 'highlight'), true);?>',
type: "GET",
cache: false,
data: {
action : 'showdates'
},
dataType: 'json',
success: function(reservations){
//alert(reservations[0][0]);
console.log(reservations);
$( "#datepicker" ).datepicker({ //initialize datepicker
defaultDate: '<?php echo $this->Time->format('Y-m-d', time()) ?>',
maxDate: '<?php echo $this->Time->format('Y-m-d', '+1 month') ?>',
dateFormat: 'yy-mm-dd',
beforeShowDay: function(date){
var y = date.getFullYear().toString(); // get full year
var m = (date.getMonth() + 1).toString(); // get month.
var d = date.getDate().toString(); // get Day
if(m.length == 1){ m = '0' + m; } // append zero(0) if single digit
if(d.length == 1){ d = '0' + d; } // append zero(0) if single digit
var currDate = y+'-'+m+'-'+d;
console.log(currDate);
/*
$.each(reservations, function(k, v){
//alert(v.date + ' ' + v.count);
if(v.date == currDate && v.count > 3){
return [true, "ui-highlight"];
}
else{
return [true];
}
});
/*for(var i = 0; i < reservations.lenght; i++){
alert(reservations[i][1]);
if(*reservations[i][1] == currDate*reservations.indexOf(currDate) >= 0){
return [true, "ui-highlight"];
}else{
return [true];
}
}*/
},
onSelect : function(dateText,inst) //when selecting date, make AJAX call to show accordion
{
$.ajax({
url: '<?php echo Router::url(array('controller' => 'streservations', 'action' => 'hours'), true);?>',
type: "GET",
cache: false,
dataType: 'json',
data: {
action: 'accord',
date: dateText
},
success: function(data){
$("#hours").accordion({collapsible: true, clearStyle: true, heightStyle: "content"});
$('#hours').empty();
$.each(data, function(k, v){
$('#hours').append('<li><h3><div>' + v.title + ' ' + v.start + '</div></h3><div>' + 'Operation: ' + v.name + '</br>' + 'Name: ' + v.title + '</br>'+ 'Time: ' + v.start + '</br>'+'</div></li>');
});
$("#hours").accordion( "refresh" );
}
});
}
});
}
});
});
更新: 因此,我将脚本版本更改为开发版本(jquery-ui.custom),现在我收到此错误:
TypeError: daySettings 未定义
unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] ||
【问题讨论】:
-
脚本的缩小版本用于生产,而不是开发。使用完整的脚本以获得更好的错误信息。
标签: javascript jquery ajax cakephp datepicker