Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.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
Javascript 在Fullcalendar jquery中显示事件?_Javascript_Jquery_Fullcalendar - Fatal编程技术网

Javascript 在Fullcalendar jquery中显示事件?

Javascript 在Fullcalendar jquery中显示事件?,javascript,jquery,fullcalendar,Javascript,Jquery,Fullcalendar,使用“events”上的函数,我无法显示我的事件,但如果我使用console中使用同一返回变量的console.log生成的字符串,我可以显示我的事件。为什么? $(document).ready(function () { var date = new Date(); var d = date.getDate(); var m = date.getMonth();

使用“events”上的函数,我无法显示我的事件,但如果我使用console中使用同一返回变量的console.log生成的字符串,我可以显示我的事件。为什么?

$(document).ready(function () {

                    var date = new Date();
                    var d = date.getDate();
                    var m = date.getMonth();
                    var y = date.getFullYear();

                    // page is now ready, initialize the calendar...
                    var calendar = $('#calendar');
                    calendar.fullCalendar({
                        // put your options and callbacks here
                        'theme': false,
                        'header': {
                            left: 'prev,next today',
                            center: 'title',
                            right: 'month,agendaWeek,agendaDay'
                        },
                        'weekends': false,
                        'defaultView': 'agendaDay',
                        axisFormat: 'HH:mm',
                        timeFormat: {
                            // for agendaWeek and agendaDay
                            agenda: 'H:mm{ - H:mm}', // 5:00 - 6:30
                            // for all other views
                            '': 'H(:mm)t'            // 7p
                        },
                        minTime: 8,
                        ignoreTimezone: true,
                        editable: true,
                        selectable: true,
                        selectHelper: true,
                        select: function (startDate, endDate, allDay, jsEvent, view) {
                            /*
                             after selection user will be promted for enter title for event.
                             */
                            var title = prompt('Event Title:');
                            /*
                             if title is enterd calendar will add title and event into fullCalendar.
                             */
                            if (title) {
                                calendar.fullCalendar('renderEvent',
                                        {
                                            title: title,
                                            start: startDate,
                                            end: endDate,
                                            allDay: allDay
                                        },
                                        true // make the event "stick"
                                );
                            }
                            calendar.fullCalendar('unselect');
                        },
                        eventDrop: function (event, delta) {
                            alert(event.title + ' was moved ' + delta + ' days\n' +
                                    '(should probably update your database)');
                        },
                        events: function getjson() {

                            var out;

                            $.ajax({
                                url: 'http://localhost:8000/calendar/api/events/events/',
                                type: 'GET',
                                async: false,
                                success: function (data) {
                                    out = JSON.stringify(data['objects']);
                                },
                                error: function () {
                                    alert('errore');
                                }
                            });
                            console.log('hshshshshsh', out);
                            return out;

                        }

我使用的json资源显示事件对象

您可以直接输入URL(如上所述):


下面的代码对我有用。它可能会发现你很有用。只需根据你的代码进行更改

 events: function (start, end, callback) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "Put your url here",
                    dataType: "json", // datatype returned by the webservice

                    success: function (data) {
                        var events = $.map(data.d, function (item, i) {
                            var event = new Object();
                            event.id = item.id;
                            event.start = new Date(item.date);
                            event.title = item.title;
                            event.color = item.color;

                            return event;
                        });
                        callback(events);

                    }, //end of Success function

                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                                          alert("StatusEvents: " + textStatus);
                                                 alert("Error: " + errorThrown);
                    }

                }); //end of Ajax Function


            } //end of events function
我的json实体如下

 [Serializable]
public class Events 
{
    public int id { get; set; }
    public string title { get; set; }
    public DateTime date { get; set; }
    public string color { get; set; }
}

它告诉我“坏请求”400状态码。。可能我必须使用GET请求而不是POST?没有POST请求是正确的…您是否传递了正确的数据类型,如数据类型:“json”?是的,我传递了。。。上面写着坏请求400,我已经抄了你的建议
 [Serializable]
public class Events 
{
    public int id { get; set; }
    public string title { get; set; }
    public DateTime date { get; set; }
    public string color { get; set; }
}