0

我在 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]); ?>
4

2 回答 2

0

我升级到 CakePHP 3.1,我不再有这个问题。

于 2016-01-04T21:23:44.590 回答
0

假设您正在运行一个混合移动应用程序,这就是您在 XMLHttpRequest 上收到错误的原因。您遇到此错误的原因是因为您的移动应用程序正在从移动设备本地提供给混合 WebView,这意味着应用程序中提供的页面的来源与您所在资源的来源不匹配尝试请求(您的提要端点。)要允许您的跨源移动应用程序连接到您的端点,您将必须在请求上设置跨源资源共享 (CORS) 标头。我实际上写了一个插件来做到这一点。 就在这里,希望对你有帮助!

于 2015-12-29T01:04:17.380 回答