简体   繁体   中英

AJAX in fullcalendar function

How can I add a ajax call into my viewRender ?

For example:

var currentMonth = moment().month();

$('#calendar').fullCalendar({

    viewRender: function(view, element){
        url: '/getevents.php',
        type: 'POST', // ERROR LINE
        fail: function() {
            alert('There was an error while fetching events.');
        }
    }

});

the error I get is this:

Uncaught SyntaxError: Unexpected token :

how can i fix this?

Here's the solution:

First you need to make an AJAX call and since you're using jQuery, use $.ajax()

var currentMonth = moment().month();

$('#calendar').fullCalendar({

    viewRender: function(view, element){
      $.ajax({
        url: '/getevents.php',
        type: 'POST',
        success: function(response) {
          // SUCCESS CODE
        },
        // ERROR LINE
        error: function() {
          alert('There was an error while fetching events.');
        }
      });
    }

});

And about the error, that's because it is what it says. You're defining object properties inside a function with the wrong syntax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM