2013-04-05 100 views
2

我想在我的本地主機上設置FullCalendar來測試它。下面的代碼:FullCalendar跨域問題

$('.calendar').fullCalendar({ 
    header: { 
     left: 'prev,next today', 
     center: 'title', 
     right: 'month,agendaWeek,agendaDay' 
    }, 
    eventSources: [ 
     { 
      url: "http://www.google.com/calendar/feeds/feed_one", 
      className: 'feed_one' 
     }, 
     { 
      url: "http://www.google.com/calendar/feeds/feed_two", 
      className: 'feed_two' 
    ] 
}) 

我在控制檯,而不是得到這個錯誤,而這些事件沒有顯示:

XMLHttpRequest cannot load http://www.google.com/calendar/feeds/feed_one. 
Origin http://localhost is not allowed by Access-Control-Allow-Origin. localhost:1 

XMLHttpRequest cannot load http://www.google.com/calendar/feeds/feed_two. 
Origin http://localhost is not allowed by Access-Control-Allow-Origin. localhost:1 

從我的研究,好像這是一個Cross-Origin-Resource-Sharing的問題,但我不」不知道如何解決它。

如果有人能夠幫助我,或者指引我走向正確的方向,我將不勝感激。

回答

4

您需要爲跨域訪問製作JSONP請求。你可以請設置以下屬性,並檢查這是否適合你。

你可以得到JSONP的詳細描述過here ...

eventSources: [ 
    { 
     url: "http://www.google.com/calendar/feeds/feed_one", 
     dataType : 'jsonp', 
     className: 'feed_one' 
    }, 
    { 
     url: "http://www.google.com/calendar/feeds/feed_two", 
     dataType : 'jsonp', 
     className: 'feed_two', 
] 
+0

後被修復謝謝。這似乎解決了錯誤。但是,日曆仍然不顯示任何事件。有關如何測試以查看問題出在哪裏的任何想法? – 2013-04-05 18:43:56

1

我有這個問題。添加到代碼<script type='text/javascript' src='fullcalendar-1.6.2/fullcalendar/gcal.js'></script>

+0

我錯過了這個文件引用,並添加它解決了這個問題。 – 2013-09-03 21:16:33

+0

我在嘗試使用這樣的lib時發現了相同的錯誤。之後,我添加了以上描述和錯誤消失。此類故障排除也幫助了一些人。所以不是我的故障排除,但你的評論是不相關的。 – 1nstinct 2014-02-27 10:45:16