views:

113

answers:

3

Hi everyone,

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 appreciated!

thanks,

+2  A: 

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'
});
Jeff T
If you can change the CF script then you can use my code above exactly. Fullcalendar will add the start and end parameters to the querystring for you, you don't have to do it in the code. Your CF script will then need to be able to handle getting start and end from the querystring and changing them from unix timestamps to date objects for you to deal with them. Does that make sense?
Jeff T
A: 

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.

A: 

How does the CFC use/access the Start/End vars that are passed in the URL?

Josh