How can I load all events on calendar using Ajax?

后端 未结 4 1792
囚心锁ツ
囚心锁ツ 2021-02-01 08:39

I want to load all events on FullCalendar using AJAX when I clicked next-previous-button in agenda-views.

I guess, when will click on

4条回答
  •  遇见更好的自我
    2021-02-01 09:13

    fullCalendar already uses ajax, so you don't have to type it. When I was starting to implement fullCalendar I used the solution of the most voted answer here:

    https://stackoverflow.com/a/25404081/3927450

    but then I could prove, that fullCalendar is in charge of making the ajax call the times the view changes without you having to do anything. I find this plugin very useful, although the documentation did not seem very clear to me.

    So this code:

    events: function(start, end, timezone, callback) {
        jQuery.ajax({
            url: 'schedule.php/load',
            type: 'POST',
            dataType: 'json',
    

    is exactly this:

    events: schedule.php/load,
    

    you only have to provide the url. Off course you have to deal with a proper JSON response from the server. Or if you need more params you can do it like this:

    events: {
    url: '/myfeed.php',
    method: 'POST',
    extraParams: {
      custom_param1: 'something',
      custom_param2: 'somethingelse'
    },
    failure: function() {
      alert('there was an error while fetching events!');
    },
    color: 'yellow',   // a non-ajax option
    textColor: 'black' // a non-ajax option
    

    }

提交回复
热议问题