Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何将ajax请求连接到事件?_Jquery_Ajax_Fullcalendar - Fatal编程技术网

Jquery 如何将ajax请求连接到事件?

Jquery 如何将ajax请求连接到事件?,jquery,ajax,fullcalendar,Jquery,Ajax,Fullcalendar,我已经创建了下面的两个函数,它们从我的API中获得了我需要的东西。但我不知道如何将其放入fullCalendar实例的“事件”部分 这是我的ajax调用: $.fn.CalendarEvents = (function () { return $.ajax("/api/exams/", { type: "GET", data: JSON.stringify(this), contentType: "application/json",

我已经创建了下面的两个函数,它们从我的API中获得了我需要的东西。但我不知道如何将其放入fullCalendar实例的“事件”部分

这是我的ajax调用:

$.fn.CalendarEvents = (function () {
    return $.ajax("/api/exams/", {
        type: "GET",
        data: JSON.stringify(this),
        contentType: "application/json",
        success: function(data, status, XHR) {
            callEvents(data);
        }
    });
});
这是我的回调函数:

function callEvents(response) {
    var calObj = [];
    $.each(response, function (index, item) {
        var evt = {
            title: item.title,
            start: item.startDateTime,
            end: item.endDateTime
        };
        calObj.push(evt);
    });
    return calObj;
    //this writes out exactly what I need to go into my calendar
    console.log(calObj);    
};
var calendar = $('#calendar').fullCalendar({
    events: getCalendarEvents
...


var getCalendarEvents = function(start, end, timezone, callback) {
    $.ajax("/api/exams/", {
        type: "GET",
        data: JSON.stringify(this), // Not sure what you are trying to do here
        contentType: "application/json",
        success: function(response, status, XHR) {
            var calObj = [];
            $.each(response, function (index, item) {
                var evt = {
                    title: item.title,
                    start: item.startDateTime,
                    end: item.endDateTime
                };
                calObj.push(evt);
             });
            // You have to execute callback that is provided in the arguments
            // with your events data
            callback(calObj);
        }
    });
};
从示例中,我看到它们使用来自URL或XML文件的JSON提要,但我只需要在上述函数中创建的javascript对象

var calendar = $('#calendar').fullCalendar({
    events: {
        //What do I put here?
    }

谢谢

根据文档
事件可以指定为一个函数:

function callEvents(response) {
    var calObj = [];
    $.each(response, function (index, item) {
        var evt = {
            title: item.title,
            start: item.startDateTime,
            end: item.endDateTime
        };
        calObj.push(evt);
    });
    return calObj;
    //this writes out exactly what I need to go into my calendar
    console.log(calObj);    
};
var calendar = $('#calendar').fullCalendar({
    events: getCalendarEvents
...


var getCalendarEvents = function(start, end, timezone, callback) {
    $.ajax("/api/exams/", {
        type: "GET",
        data: JSON.stringify(this), // Not sure what you are trying to do here
        contentType: "application/json",
        success: function(response, status, XHR) {
            var calObj = [];
            $.each(response, function (index, item) {
                var evt = {
                    title: item.title,
                    start: item.startDateTime,
                    end: item.endDateTime
                };
                calObj.push(evt);
             });
            // You have to execute callback that is provided in the arguments
            // with your events data
            callback(calObj);
        }
    });
};