我是在我的Fullcalendar中实现JSON提要的最后一步,我遇到了回调函数的问题。我一直得到错误“unidentified is not a function”或“unexpected identifier”取决于我放置“callback(event)”函数的位置。
以下是整个Ajax请求:
App.controller('calCtrl', function ($scope, $log, $state) {
$scope.eventSources = [{
events: function(start, end, timezone, callback) {
$.ajax({
url: 'url/calendarConnect.php',
dataType: 'json',
success: function(response) {
var event = [];
$(response).find('events').each(function() {
event.push({
title: $(this).attr('title'),
start: $(this).attr('start'),
end: $(this).attr('end')
});
});
}
});
callback(event);
}
}]
});
非常感谢任何关于问题的想法。
答案 0 :(得分:0)
移动'回调'进入你的ajax请求的成功函数。我假设您不希望调用回调,除非ajax请求成功。此外,您还没有提及“事件”。如果回调在函数之外,则为variable。
success: function(response) {
var event = [];
$(response).find('events').each(function() {
event.push({
title: $(this).attr('title'),
start: $(this).attr('start'),
end: $(this).attr('end')
});
});
callback(event);
}