gpt4 book ai didi

javascript - 与 fullcalendar 和 google calendar 相同的域

转载 作者:行者123 更新时间:2023-11-28 02:01:33 25 4
gpt4 key购买 nike

我正在尝试在我使用 fullcalendar 框架开发的网页中显示谷歌日历中的一些数据。

但是我遇到了同域来源的问题...我不知道如何解决它。在文档中,fullcalendar 说:

<script type='text/javascript'>

$(document).ready(function() {
$('#calendar').fullCalendar({
events: 'http://www.google.com/your_feed_url/'
});
});

</script>

但是通过我的公共(public)日历执行此操作只会给我带来问题。

我尝试使用服务器中的 php 读取 json 格式的日历,但结果非常相似。没有收到有关域的问题,但未显示事件。我收到有关 formatDate 未初始化的错误,因此我认为我没有读取事件。

知道如何解决这个问题吗?我想,如果fullcalendar允许用gcalendar做到这一点,那就意味着它可以做到。

我在 json 中添加了一些事件:

{"version":"1.0","encoding":"UTF-8","feed":    {"xmlns":"http://www.w3.org/2005/Atom","xmlns$openSearch":"http://a9.com/-    /spec/opensearchrss/1.0/","xmlns$gCal":"http://schemas.google.com/gCal/2005","id":    {"$t":"http://www.google.com/calendar/feeds/aristeidhsxr%40gmail.com/public/basic"},"update    d":{"$t":"2013-08-22T09:47:26.000Z"},"category":    [{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://schemas.google.com/g/2005    #event"}],"title":{"$t":"aristeidhsxr@gmail.com","type":"text"},"subtitle":    {"$t":"aristeidhsxr@gmail.com","type":"text"},"link":    [{"rel":"alternate","type":"text/html","href":"http://www.google.com/calendar/embed?    src=aristeidhsxr%40gmail.com"},{"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml","href":"http://www.google.com/calendar/feeds/aristeidhsxr%40gmail.com/public/basic"},{"rel":"http://schemas.google.com/g/2005#batch","type":"application/atom+xml","href":"http://www.google.com/calendar/feeds/aristeidhsxr%40gmail.com/public/basic/batch"},{"rel":"self","type":"application/atom+xml","href":"http://www.google.com/calendar/feeds/aristeidhsxr%40gmail.com/public/basic?alt=json&max-results=25"}],"author":[{"name":{"$t":"ΑÏιστείδης ΧÏήστου"},"email":{"$t":"aristeidhsxr@gmail.com"}}],"generator":{"$t":"Google Calendar","version":"1.0","uri":"http://www.google.com/calendar"},"openSearch$totalResults":{"$t":19},"openSearch$startIndex":{"$t":1},"openSearch$itemsPerPage":{"$t":25},"gCal$timezone":{"value":"Europe/Madrid"},"gCal$timesCleaned":{"value":0},"entry":[{"id":{"$t":"http://www.google.com/calendar/feeds/aristeidhsxr%40gmail.com/public/basic/2gh1aqf61krdvgr85eseoclr64"},"published":{"$t":"2013-08-22T09:47:26.000Z"},"updated":{"$t":"2013-08-22T09:47:26.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://schemas.google.com/g/2005#event"}],"title":{"$t":"dghhfdg","type":"html"},"summary":{"$t":"Cuándo: vie 30 de ago de 2013 21:30 al 22:30 \nCEST\u003cbr\u003e\n\n\n\u003cbr\u003eEstado del evento: bekräftad","type":"html"},"content":{"$t":"Cuándo: vie 30 de ago de 2013 21:30 al 22:30 \nCEST\u003cbr /\u003e\n\n\n\u003cbr /\u003eEstado del evento: bekräftad","type":"html"},"link":[{"rel":"alternate","type":"text/html","href":"http://www.google.com/calendar/event?eid=MmdoMWFxZjYxa3JkdmdyODVlc2VvY2xyNjQgYXJpc3RlaWRoc3hyQG0","title":"alternate"}

这是 json 文件的一部分,不完整。

我尝试按照一位用户的说法直接放置几个事件:

$(document).on('pageshow','#agenda',function(){    

$('#calendar').fullCalendar({
events: [{
title: 'Event 1', start: '2013-08-26T19:10:00Z',
end: '2013-08-28T19:20:00Z'
},{
title: 'Event 2', start: '2013-08-27T16:25:00Z',
end: '2013-08-27T18:45:00Z'
}]
});
});

但我收到一条错误消息:

Uncaught TypeError: Cannot read property 'formatDate' of undefined gcal.js:11
(anonymous function) gcal.js:11
(anonymous function) gcal.js:107

最佳答案

您确定在 php 中正确解析了来自 http://www.google.com/your_feed_url/ 的事件吗?事件开始和结束日期必须采用 ISO 8601 格式,例如 2013-07-09T19:10:00-04:00。您可以使用 fullcalendar $.fullCalendar.formatDate(from, format); 转换日期和时间。

您也可以使用 Google Calendar Api获取事件。

事件必须如下所示:

events: [{
title: 'Event 1', start: '2013-07-09T19:10:00-04:00',
end: '2013-07-09T19:20:00-04:00', allDay: false
},{
title: 'Event 2', start: '2013-08-22T16:25:00-04:00',
end: '2013-08-22T18:45:00-04:00', allDay: true
}]

对于公共(public)谷歌日历,您可以执行以下操作:

var url = 'http://google.com/calendar/feeds/test@group.calendar.google.com/public/full?alt=json';
$.ajax({
url: url,
dataType: 'jsonp',
success: function(response){
var googleEvents = new Array();
for(var i = 0; i < response.feed.entry.length; i ++){
googleEvents[i] = {
title : response.feed.entry[i].title.$t,
start: response.feed.entry[i].gd$when[0].startTime,
end: response.feed.entry[i].gd$when[0].endTime
};
}
//init events
calendar = $('#calendar-container').fullCalendar({
events: googleEvents
});
}
});

参数alt指定响应的格式。

关于javascript - 与 fullcalendar 和 google calendar 相同的域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18376454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com