Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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 CakePHP中数据数组的Ajax提交不工作_Javascript_Jquery_Cakephp 2.0_Fullcalendar - Fatal编程技术网

Javascript CakePHP中数据数组的Ajax提交不工作

Javascript CakePHP中数据数组的Ajax提交不工作,javascript,jquery,cakephp-2.0,fullcalendar,Javascript,Jquery,Cakephp 2.0,Fullcalendar,我正在制作一个日程安排日历,调度员可以将组织的成员拖放到Fullcalendar上。我已经将丢弃的事件存储到了一个数组对象arrayOfEvents中。我想让Ajax提交到CakePHP add函数,将数据插入我的事件数据库,然后重新加载日历。这是我的密码 要删除的外部事件: /* initialize the external events -----------------------------------------------------------------*/

我正在制作一个日程安排日历,调度员可以将组织的成员拖放到Fullcalendar上。我已经将丢弃的事件存储到了一个数组对象arrayOfEvents中。我想让Ajax提交到CakePHP add函数,将数据插入我的事件数据库,然后重新加载日历。这是我的密码

要删除的外部事件:

/* initialize the external events
     -----------------------------------------------------------------*/

    $('#external-events div.external-event').each(function() {

        // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
        // it doesn't need to have a start or end
        var eventObject = {
            title: $.trim($(this).text()), // use the element's text as the event title
            userId: this.id
        };

        // store the Event Object in the DOM element so we can get to it later
        $(this).data('eventObject', eventObject);

        // make the event draggable using jQuery UI
        $(this).draggable({
            zIndex: 999,
            revert: true, // will cause the event to go back to its
            revertDuration: 0  //  original position after the drag
        });

    });
完整日历:

     /* initialize the calendar
     -----------------------------------------------------------------*/
    var arrayOfEvents = [];
    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'agendaWeek,agendaDay'
        },
        defaultView: 'agendaWeek',
        editable: true,
        events: [
<?php foreach ($users as $user) {
foreach ($user['Event'] as $event):
    ?>
                    {
                        start: '<?php echo $event['start_date']; ?>',
                        end: '<?php echo $event['end_date']; ?>',
                        title: '<?php echo $event['title']; ?>',
                        allDay: false,
                        color: '#077169'
                    },
<?php endforeach;
}
?>
        ],
        droppable: true, // this allows things to be dropped onto the calendar !!!
        drop: function(date, allDay) { // this function is called when something is dropped

            // retrieve the dropped element's stored Event Object
            var originalEventObject = $(this).data('eventObject');
            // we need to copy it, so that multiple events don't have a reference to the same object
            var copiedEventObject = $.extend({}, originalEventObject);
            // assign it the date that was reported
            copiedEventObject.start = date;
            copiedEventObject.end = (date.getTime() + 3600000) / 1000; // default shift length is 1 hour
            copiedEventObject.userId = originalEventObject.userId;
            copiedEventObject.allDay = false;
            // render the event on the calendar
            // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
            $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
            // Push events into array
            arrayOfEvents.push(copiedEventObject);
            //todo: the calendar needs to insert events into the event calendar. 
            console.log(arrayOfEvents);
        }
    });



});
我知道这是一个漫长的过程,但任何意见都会受到欢迎

function updateSchedule()
 {
     var arrayOfEvents = [];
    //var data = "numOfEvents=" + arrayOfEvents.length; //original
    var data = "numOfEvents=" + arrayOfEvents.length;


    // You can get all events out of the array here
    for (var i = 0; i < arrayOfEvents.length; i++) {
        var event = arrayOfEvents[i];
        data += "&id" + i + "=" + event.id
                + "&start" + i + "=" + event.start
                + "&end" + i + "=" + event.end;
    }

    // Make your ajax post here
    $.ajax({
        type: "POST",
        url: "<?php echo $this->webroot; ?>events/add",
        data: data,
        success: function(response) {
            alert('done!');
        },
        fail: function(response) {
            alert("error");
        }

    });
public function add() {
    $this->autoRender = false;
    if ($this->RequestHandler->isAjax()) {
        Configure::write('debug', 0);
    }
    if (!empty($this->data)) {

        if ($this->Event->save($this->data)) {
            echo 'Record has been added';
        } else {
            echo 'Error while adding record';
        }
    }
}