JQuery的FullCalendar麻烦从阿贾克斯成功调用rerenderEvents麻烦、FullCalendar、JQuery、阿贾克斯

2023-09-11 01:25:41 作者:枕星河同眠

由于某些原因,我不能让日历中选择一个POST之后重新呈现。一切顺利的话到这一点:

For some reason, I cannot get the calendar to rerender after a POST. All goes well up to that point:

$('#calendar').fullCalendar({
    ...
    select: function (startDate, endDate) {
        $.ajax({
            url: 'data.php',
            type: "POST",
            data: {
                'start':startDate,
                'end':endDate,
                }
            success: $('#calendar').fullCalendar('rerenderEvents')
            }
     ...
    });

数据职位成功,我的PHP脚本添加新的事件数据库就好了。唯一的问题是,日历不被重新呈现与数据库中的新的数据。

The data posts successfully, my php script adds the new event to the database just fine. The only problem is that the calendar is not being rerendered with the new data in the database.

如果我刷新页面(F5在Firefox)新的事件被渲染。很显然,我需要的事件,只要它一直致力于数据库显示出来。我不能指望我的用户刷新页面。

If I refresh the page (F5 in Firefox) the new event is rendered. Obviously, I need the event to show up as soon as it has been committed to the database. I can't expect my user to refresh the page.

我已经做了这样的成功说明书的许多排列,如:

I have done many permutations of this success statment, eg:

function () {
    $('#calendar').fullCalendar('rerenderEvents');
}

和(与我的PHP返回'成功')

and (with my php returning 'success'),

function (data) {
    if (data === 'success') $('#calendar').fullCalendar('renderEvents');
}

不过,无论怎样,新的事件添加到数据库中只显示了,如果我刷新屏幕。任何人都可以提出什么,我可能是做错了?

However, no matter what, the new event added to the database only shows up if I refresh the screen. Can anyone suggest what I might be doing wrong?

推荐答案

尝试:

$('#calendar').fullCalendar("refetchEvents");

更新2013年1月31日。

Update 2013-01-31.

这是可行的,因为你是迫使FC再次重读事件源和渲染的日历。

That works because you are forcing FC to reread the event source and render the calendar again.

但是,如果有时是蛮力解决方案,另一种方式来达到相同的(如果可能)就是要做到这一点,比如说在 dayClick 创建一个新的事件时

However, if that is sometimes a brute force solution, another way to achieve the same (when possible) is to do this, say in dayClick when creating a new event:

更新事件-DB使用 $。阿贾克斯 创建相应的新事件: yourcal.fullCalendar(renderEvent',{ID:X,启动:timest,结束:timend,标​​题:TXT},真); update event-DB using $.ajax create the corresponding new event: yourcal.fullCalendar('renderEvent', {id:x,start:timest,end:timend,title:txt}, true);