views:

119

answers:

2

Hello, I am fairly new to the FullCalendar, but totally love it's functionality. I am trying to use the dayClick function. Perhaps someone can guide me in the right direction.

I currently have this.

dayClick: function (date, allDay, jsEvent, view) { var titleNew = prompt('Event Title:'); var thedate1 = formatDate(date);

            $.ajax({
                url: "classes/class.Post.php?a=dayClickCalendarEvent",
                dataType: 'json',
                data: { 
                      title: titleNew,
                      start: thedate1,
                      end: thedate1
                },
                success: function (data, response, event, date) {

                    $('#calendar').fullCalendar('renderEvent', titleNew);
                },
                error: function () {
                    alert("Oops! Something didn't work");
                }
            });
        },

My problem is that I can't get the event to RENDER to the calendar no matter what. Am I missing something? I am using the calEvent, where I found it on another StackOverflow post.

Any help would be appreciated. Thank you.

A: 

I think the problem is in this statement $('#calendar').fullCalendar('renderEvent', titleNew);

titleNew is a string, and the renderEvent function takes a calEvent object.

From the FullCalendar Documentation:

event must be an Event Object with a title and start at the very least. Normally, the event will disappear once the calendar refetches its event sources (example: when prev/next is clicked). However, specifying stick as true will cause the event to be permanently fixed to the calendar.

I'm curious why you are using an Ajax call though, it doesn't seem like you are doing anything with it.

partkyle
If I use something like, $('#calendar').fullCalendar('renderEvent', event, stick); it still causes problems. In my other code when i'm updating an event I use:$('#calendar').fullCalendar('updateEvent', event, stick);and it works great. But only when i'm adding it doesn't seem to want to add. Inside the AJAX call i'm using that to add it to a database under the URL calling a switch statement with my data variables. Is this a bad practice?
Justin
I'm sure you have already checked, but does the 'success' event get fired? Have you tried putting an alert in there? What are you getting from the server? I see that you are calling for json, but you aren't using it. Also - the signature seems wrong to me, it should be success(data, textStatus, XMLHttpRequest). I don't know what the 'date' member is.
partkyle
+1  A: 

Hey I thank you for your responses, I was able to use this code and it responds great!

dayClick: function (date, allDay, jsEvent, view) { var titleNew = prompt('Event Title:'); var thedate1 = formatDate(date);

            $.ajax({
                url: "classes/class.Post.php?a=dayClickCalendarEvent",
                dataType: 'json',
                data: { 
                      title: titleNew,
                      start: thedate1,
                      end: thedate1
                },
                success: function (data, response, event, date) {
                    //alert("success here");
                    $('#calendar').fullCalendar('renderEvent',
                    {
                        title: titleNew,
                        start: thedate1,
                        end: thedate1
                    }, true);
                },
                error: function () {
                    alert("Oops! Something didn't work");
                }
            });
        },
Justin
You know the `thedate1` can just be a date object (e.g. `thedate1 = new Date();`. But I'm glad you got it working.
fudgey
Yeah potentially, but you still need to format the date, which I used a custom function for into a capable MySQL specific date (ie: 2010-08-02 23:30). Unless I'm missing something?
Justin