Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Full Calendar json event source syntax

I'm trying to use full calendar to load events from a json source. The json is from a URL like a feed, "mysite.com/getEvents" (which returns a json event object). Right now it returns an object

{"allDay":false,"end":1325577600,"start":1325577600}

I tried

$('#calendar').fullCalendar({
    events: 'mysite.com/getEvents'
});

But nothing happens. I know my json is missing the title and the id. So we have 2 questions.

  1. What is the proper way to get the events from a json url
  2. How do I go about generating an id for every event created?
like image 914
EKet Avatar asked Mar 21 '12 05:03

EKet


People also ask

How do you pass events in FullCalendar?

Visiting the URL of a JSON feed is one of the ways FullCalendar fetches Event Objects. This action occurs when the user clicks prev/next or changes calendar views. FullCalendar will determine the date-range it needs events for and will pass that information along in GET parameters.

How do I create a dynamic event in FullCalendar?

although it is not specified on the fullcalender site, it is necessary to assign a value to the "allday" parameter to be able to add new events dynamically. If you set this value to "false", it will not add the event to the AllDay row. If you do "true" it will add to the AllDay row. Save this answer.

What is event in JSON?

When published to Amazon SNS, events are sent in the SNS Message as an array of JSON objects that are encoded as strings. Each object in the array is one event. Valid properties vary by the type of event.

How do I start and end date in FullCalendar?

We can get start date by getView event with intervalStart. We can get end date by getView event with intervalEnd. var month = $('#calendar'). fullCalendar('getView').


3 Answers

When I use the syntax in the accepted answer, I get four events on the calendar, not two. The two extra are bizarrely titled "12:44". On a hunch, I removed the "0" and "1" lines and now it works perfectly:

[
  {
    "title": "Ceramics",
    "id": "821",
    "start": "2014-11-13 09:00:00",
    "end": "2014-11-13 10:30:00"
  },
  {
    "title": "Zippy",
    "id": "822",
    "start": "2014-11-13 10:00:00",
    "end": "2014-11-13 11:30:00"
  }
]
like image 77
shacker Avatar answered Oct 14 '22 23:10

shacker


You should try forming the JSON so it has all the required fields. For example, on my project the following is sufficient:

  • id
  • title
  • start
  • end
  • allDay

I think the ID only has to be unique for that instance of the JSON feed, so you could just have a counter incrementing in the server-side script that generates the JSON.

Example output from the JSON script:

[
    "0",
    {
        "allDay": "",
        "title": "Test event",
        "id": "821",
        "end": "2011-06-06 14:00:00",
        "start": "2011-06-06 06:00:00"
    },
    "1",
    {
        "allDay": "",
        "title": "Test event 2",
        "id": "822",
        "end": "2011-06-10 21:00:00",
        "start": "2011-06-10 16:00:00"
    }
]
like image 25
Matt Healy Avatar answered Oct 14 '22 23:10

Matt Healy


I know this is an old post but others may be looking for this...

You need to have brackets around your json response, it seems to be expecting an array of objects:

[
    {
        "title":"foo1",
        "id":"123",
        "start":"2016-02-12T10:30:00",
        "end":"2016-02-12T12:30:00"
    },

    {
        "title":"foo2",
        "id":"456",
        "start":"2016-02-14T10:30:00",
        "end":"2016-02-14T12:30:00"
    }
]
like image 40
Jeff K Avatar answered Oct 14 '22 22:10

Jeff K