开发者

Fullcalendar not display return data

开发者 https://www.devze.com 2023-01-09 11:14 出处:网络
I have a coldfusion cfc that i call to query events between the start and end date. Here is my script:

I have a coldfusion cfc that i call to query events between the start and end date. Here is my script:

$(document).ready(function() {

var calendar = $('#calendar').fullCalendar({
  events: function(start, end, callback) {
$.ajax({
    type: "GET",
    url: 'cfc/forecast.cfc?method=GetForecast&returnformat=plain',
    data: {
         startDate: start.getDate(),
         startMonth: start.getMonth(),
         startYear: start.getFullYear(),
                 endDate: end.getDate(),
         endMonth: end.getMonth(),
         endYear: end.getFullYear()
    },
    success: function(data) {
        callback(data);
    }
});
 } 
 });
});

In firebug the return data looks like this:

[
  {"ID": 16, "start": "2010-01-04 00:00:00.0", "end": "", "title": "AM 2 Hours: 2 - 2"},
  {"ID": 16, "start": "2010-01-04 00:00:00.0", "end": "", "title": "AM 2 Hours: 2 - 2"},
  {"ID": 16, "start": "2010-01-04 00:00:00.0", "end": "", "title": "PM 2 Hours: 2 - 2"},
  {"ID": 16, "start": "2010-01-04 00:00:00.0", "end": "", "title": "PM 2 Hours: 2 - 2"}
] 

I'm new to Javascript, jQuery and FullCalendar so please forgive me. I know I'm missing something but can't figure out what it is. Any suggestions is much appreciat开发者_StackOverflow中文版ed!

thanks,


There are a few things that it might be.

1) All the ids are the same. If you don't specifically use them you can not include them and fullcalendar will auto assign an ID.

2) It might be case sensitive. The JSON I get back has it as id instead of ID.

3) Are these supposed to be all day events? If so use the "allDay": true property in the JSON. Since there is no end date I'm assuming it is an all day thing.

Give those a try. But also ...

If you have control over the ColdFusion script that you are calling, you can change it to just receive a start and end parameters that are timestamps, and return the proper JSON. Then you can just pass in the URL as a string to the events: property and it takes care of everything for you.

$('#calendar').fullCalendar({
  events: 'cfc/forecast.cfc?method=GetForecast&returnformat=plain'
});


I found the solution here http://www.jamesnetherton.com/blog/2008/05/04/Converting-Unix-timestamp-values-in-ColdFusion/. I needed to convert the start and end time in order to use in my sql query.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号