[英]AJAX in fullcalendar function
How can I add a ajax call into my viewRender
? 如何将ajax调用添加到
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 :
未捕获到的SyntaxError:意外令牌:
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()
首先,您需要进行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.');
}
});
}
});
And about the error, that's because it is what it says. 关于错误,那是因为它就是它所说的。 You're defining object properties inside a function with the wrong syntax.
您正在使用错误的语法在函数内定义对象属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.