簡體   English   中英

FullCalendar JSON Feed無法正常工作:我的日歷未將JSON Feed中的數據放到我的網頁上

[英]FullCalendar JSON Feed not working: my calendar doesn't put the data from the JSON feed onto my webpage

為什么我的日歷沒有將JSON提要中的數據放到我的網頁上?

<script type='text/javascript'>
$(document).ready(function() {
    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
    var calendar = $('#calendar').fullCalendar({
        events: 'myfeed.php',
    header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        selectable: true,
        selectHelper: true,
    eventSources: [

    // your event source
    {
        url: '/myfeed.php', // use the `url` property
        color: 'red',    // an option!
        textColor: 'black'  // an option!
    }
    // any other sources...
],
  eventClick: function(calEvent, jsEvent, view) {
if (!confirm("Are you sure you want to delete this?")) {
    }
else
{
    // remove calender, and post the info to page 
$.post("mybook.php", { idnumber: calEvent.id, remove: '1' } );
$('#calendar').fullCalendar('removeEvents', [calEvent.id]);
}
}
    });     
});
</script>

JSON Feed PHP代碼

<?php    $arr = array('id' => '1', 'title' => 'Apples', 'start' => '1372530615', 'end' => '1372537615', 'allDay' => false);
echo json_encode($arr);
?>

Charles Web調試器顯示該腳本正在評估正確的頁面,並且有響應。 但是,我的日歷什么也沒做。 :(我以為可能是因為我在使用SSL,但是我嘗試了兩種方式。

將我的代碼簡化為

<script type='text/javascript' src='jquery-1.9.1.min.js'></script>
<script type='text/javascript' src='fullcalendar.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
var calendar = $('#calendar').fullCalendar({
    events: 'myfeed.php'
});     
});
</script>

JSON Feed輸出

{"id":"1","title":"Apples","allDay":false,"start":"1372507615","end":"1372537615"}

如果您已經在使用events屬性,請刪除eventSources

必須將[]放在我的JSON輸出周圍。

我想確認上面接受的答案。 我已經看到了幾個有關FullCalendar中未顯示的事件的問題,特別是JSON,而解決方案似乎與語法有關。 您必須准確地給FullCalendar所要看到的內容,關於這一點的文檔尚不清楚。 期待大量的反復試驗。

我遇到了與同一問題有關的問題,並進行了以下操作以使其起作用:

  1. 確保末尾有方括號[]
  2. 確保最后沒有多余的逗號 (這就是我的意思)-顯然,在使用paramenters內​​聯時可以使用它,但是從JSON加載時會出現此問題
  3. 對fiend和value使用雙引號。
  4. 我最終重寫了php以創建一個對象數組,將值加載到該數組中,然后將其轉換為JSON(這解決了上述所有JSON格式問題)

我的JSON輸出如下所示:

[{"title":"Vishal","start":"2018-01-12 00:00:00","end":"2018-01-12 10:00:00"},{"title":"Vishal","start":"2018-01-14 14:00:00","end":"2018-01-14 15:00:00"}]

我的PHP代碼如下所示:

$data = array();

foreach($results as $run)
{

    $obj = (object) [
    'title' => $run->firstname,
    'start' => $run->startdatetime,
    'end' => $run->enddatetime
    ];

    $data[] = $obj;

}
echo json_encode($data);

我希望這有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM