2016-12-01 115 views
2

我在我的Symfony項目中使用FullCalendar,我想從數據庫加載事件並在用戶的日曆中顯示它們。 根據文檔,我在我的calendar.html.twig頁面上創建了一個AJAX請求到服務器,並在localStorage中存儲響應。這是我做了什麼:將日曆數據加載到FullCalendar

$(document).ready(function() { 
    var events = []; 
    $.ajax({ 
     url: '{{ path('property.get.reservations') }}', 
     method: 'post', 
     data: { 
      'propertyId': {{ propertyId }} 
     }, success: function (data) { 
      console.log('running script within calendar.html.twig') 
      $.each(data, function (key, value) { 
       var event = JSON.stringify(value); 
       events.push(event); 
      }); 
      localStorage.setItem('events', events); 
     } 
    }); 
}); 

接下來,我試圖用這個數據蓄能我calnedarService.js這樣:

$('#calendar').fullCalendar({ 
    selectable: false, 
    header: { 
     left: 'prev,next', 
     center: 'title', 
     right: '' 
    }, 
    editable: true, 
    events: localStorage.getItem('events'), 
    /* another code */ 

我在控制檯中的錯誤:

找不到路線「GET /admin/property/edit/1/%7B%22id%22:1,%22start%22:%222016-12-04T00:00:00.000Z%22,%22end%22:% 222016-12-07T00:00:00.000Z%22%7D「(來自」my_host「)

因此,由於我不知道的原因,fullCalendar嘗試生成路由,使用參數從AJAX獲取。

任何幫助將讚賞

+1

的錯誤似乎無關的代碼,你當您發出POST請求時發佈,但錯誤指的是GET –

+0

,這就是爲什麼我在這裏發佈我的問題 - 腳本不必提出任何請求 - 它只是從localStorage讀取數據 –

+0

我已經解決了我的問題使用Twig變量而不是ajax-re任務,但如果有人知道如何在渲染日曆之前加載事件 - 請讓我知道:) –

回答

0

爲我工作,只是把這個網址的數據:

'admin/property/edit/' 

id爲VAR在URL的末尾