JSON无法从URL获取完整日历中的活动 [英] JSON Won't get events in Full Calendar from URL
问题描述
我们正尝试通过网址将我们的活动加载到完整日历,但事件不会加载。我已经包含了下面的JS以及来自我们的URL / API的JSON响应。
非常感谢!
URL / API JSON响应:
[{start:2016-04-012T15:30:00,end: 04-12T16:30:00,title:Calendar 1,allDay:false,id:a41380d1fbbaa819}]
$ b JS:
$(document).ready(function() {
$('#calendar')。fullCalendar({
// theme:true,
header:{
left:'prev,next today',
center:'title',
right:'month,agendaweek,agendaDay'
},
defaultDate:moment().format(YYYY-MM-DD),
editable:true,
events:{
url:'MY URL,I DIDN''T POST IT HERE TO PREP IT PRIVATE',
error:function(){
$('#script-warning')。show();
},
success:function(){
警报(成功:你现在可以在这里做你的东西。你不需要Ajax。完整的日历会做ajax调用吗? );
}
},
loading:function(bool){
$('#loading')。toggle(bool);
}
});
});
好吧,弄清楚是非常棘手的,但是你的JSON确实不合格。
查看开始属性在你的对象中,看看日期是如何写入的 - 它不是日期字符串。
你有这个:
2016 -04- 0 12T15:30:00
应为:
2016-04-12T15:30:00 $ p $ (请注意突出显示)。
另请参阅此答案: JavaScript对象与JSON
当你需要一个Javascript对象时,你的问题似乎有一个JSON 字符串。
另外,请参阅我的JSBIN 此处看到w帽子发生了。
We're trying to load our events to Full Calendar from a URL, but the events won't load. I've included th JS below, as well the JSON response from our URL/API.
Thanks so much!URL/API JSON Response:
[{"start":"2016-04-012T15:30:00","end":"2016-04-12T16:30:00","title":"Calendar 1","allDay":"false","id":"a41380d1fbbaa819"}]
JS:
$(document).ready(function() { $('#calendar').fullCalendar({ //theme: true, header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, defaultDate: moment().format("YYYY-MM-DD"), editable: true, events: { url: 'MY URL, I DIDN\'T POST IT HERE TO KEEP IT PRIVATE', error: function() { $('#script-warning').show(); }, success: function(){ alert("successful: You can now do your stuff here. You dont need ajax. Full Calendar will do the ajax call OK? "); } }, loading: function(bool) { $('#loading').toggle(bool); } }); });
解决方案Well, it was tricky to figure out but your JSON is indeed ill-formed.
Check out the "start" property in you object and see how the date is written - it's not a Date string.
You have this:
2016-04-012T15:30:00should be :
2016-04-12T15:30:00(note the highlight).
Also see this answer: Javascript object Vs JSON
Your problem seems to be having a JSON string when you need a Javascript object.
Also, see my JSBIN here to see what's happening.
这篇关于JSON无法从URL获取完整日历中的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!