如何将 ajax 调用添加到我的 viewRender
中?
例如:
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.');
}
}
});
我得到的错误是这样的:
Uncaught SyntaxError: Unexpected token :
我该如何解决这个问题?
最佳答案
解决方案如下:
首先您需要进行 AJAX 调用,并且由于您使用的是 jQuery,因此请使用 $.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.');
}
});
}
});
关于错误,那是因为它就是这样说的。您正在使用错误的语法在函数内定义对象属性。
关于javascript - 全日历功能中的 AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43860218/