使用Ajax在Fullcalendar中保存事件

Saving event in Fullcalendar using Ajax

本文关键字:保存 事件 Fullcalendar Ajax 使用      更新时间:2023-09-26

我使用的是fullcalendar,我想在单击日历时保存事件。

这就是我到目前为止所拥有的,它处理表单中提交的元素,而不是日历中的元素,例如,我无法获得开始日期。

$('#calendar').fullCalendar({
...
select: function(start, end, allDay, event, resourceId) { 
$('#add_appt').modal(); //openthemodal
$(document).ready(function(){
    $('#EventAdd').submit(function(e) {
        SubmitAppointment();
        e.preventDefault();
    });
});
function SubmitAppointment(){
    hideshow('loading',1);
    error(0);
    $.ajax({
        type: "POST",
        url: "ajax.events.add.php",
// If I try this, I get all the elements of the form but no value for start I think it's my syntax that is wrong
        data: $('#EventAdd').serialize(),start: start, 
// If I try this, I get the start date but I don't know how to include the vales in EventAdd
        data: 'start='+ start,
        dataType: "json",
        success: function(msg){
            if(parseInt(msg.status)==1){
                $('#add_appt').modal('hide');
                //window.location=msg.txt;
            }else if(parseInt(msg.status)==0){
                error(1,msg.txt);
            }
        hideshow('loading',0);
        }
    });
}

有人能帮我学语法吗?因为我认为这才是真正的问题所在。

如果您想发送所有的<form>值和start值,我认为您必须按如下方式传递ajax调用的data参数:

data: $('#EventAdd').serialize() + "&start=" + start

所以我找到了自己问题的答案:

我使用这个:

data: 'start='+ start+$('#EventAdd').serialize(),

而不是这个

data: $('#EventAdd').serialize(),start: start,