我在 cakephp 3.x 上使用完整日历,并且仅在移动设备上收到此错误消息“XMLHttpRequest cannot load https://www.utahreia.org/events/feed ... No 'Access-Control-Allow-Origin ' 请求的资源上存在标头。因此,不允许访问源 ' https://utahreia.org '。
在桌面上,事件加载正常,只是我收到错误的移动设备,我不知道为什么。提要用于从数据库中获取事件并将它们呈现到此 url:完整日历
这里是饲料方法:
public function feed($id=null) {
$this->layout = "ajax";
$vars = $this->request->query([]);
$conditions = ['UNIX_TIMESTAMP(start) >=' => $vars['start'], 'UNIX_TIMESTAMP(start) <=' => $vars['end']];
$events = $this->Events->find('all', $conditions)->contain(['EventTypes']);
foreach($events as $event) {
if($event->all_day === 1) {
$allday = true;
$end = $event->start;
} else {
$allday = false;
$end = $event->end;
}
$event_img[] = array(
'id' => $event->id,
'title'=> $event->title,
'start'=> $event->start,
'end' => $end,
'allDay' => $allday,
'url' => Router::url('/') . 'events/view/'.$event->id,
'details' => $event->details,
'className' => $event->event_type->color
);
}
$this->set("json", json_encode($event_img));
$this->set(compact('user'));
}
这是ready.js:
jQuery(document).ready(function( $ ) {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
header: {
left: 'title',
center: '',
right: 'today agendaDay,agendaWeek,month prev,next'
},
defaultView: 'month',
fixedWeekCount: false,
firstHour: 8,
aspectRatio: 2,
editable: adminEdit,
events: plgFcRoot + "events/feed"
})
});
完整日历页面:
<div class="page-wrap">
<div class="Calendar index">
<div id="calendar"></div>
</div>
</div>
<script type="text/javascript">plgFcRoot = "https://www.utahreia.org/";</script>
<?php if (isset($current_user) && $current_user['role'] === 1): ?>
<script type="text/javascript">adminEdit = true;</script>
<?php else: ?>
<script type="text/javascript">adminEdit = false;</script>
<?php endif; ?>
<?= $this->Html->css('/full_calendar/css/fullcalendar', ['plugin' => true]); ?>
<?= $this->Html->css('/full_calendar/css/jquery.qtip.min', ['plugin' => true]); ?>
<?= $this->Html->script('/full_calendar/js/lib/jquery.min.js', ['plugin' => true]); ?>
<?= $this->Html->script('/full_calendar/js/lib/moment.min.js', ['plugin' => true]); ?>
<?= $this->Html->script('/full_calendar/js/fullcalendar.js', ['plugin' => true]); ?>
<?= $this->Html->script('/full_calendar/js/jquery.qtip.min.js', ['plugin' => true]); ?>
<?= $this->Html->script('/full_calendar/js/ready.js', ['plugin' => true]); ?>