无法将jQuery .val()传递给fullCalendar json数据函数

时间:2014-07-10 14:55:19

标签: jquery fullcalendar

我正在尝试传递一个从jQuery $('#user-selector')获得的值.val()

作为fullCalendar json数据函数的参数,但无论出于何种原因,它都不会发布值,它只是空白。当我控制台记录该值时,它确实包含它应该...

$("select#user-selector").on('change',function(){

    console.log($('#user-selector').val());

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


$('#calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
},
defaultDate: getCurrentDate(), 
    editable: true,
    //events: 
    events: {
        url: 'php/event_handler.php', 
        type: 'GET',
        data: {
            user_id: $('#user-selector').val()
    },
    error: function() {
        alert('Unable to load the requested events, please refresh and try again!');
    }
},

1 个答案:

答案 0 :(得分:0)

user_id: $('#user-selector').val()仅被评估一次(在document.Ready我在猜测)并且不构成约束。

以下是您可以做的事情:

$('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            defaultDate: getCurrentDate(), 
            editable: true,
            //events: 
            events: {
                url: 'php/event_handler.php', 
                type: 'GET',
                data: function() {
                        return {
                            user_id: $('#user-selector').val()
                    };
                },
                error: function() {
                    alert('Unable to load the requested events, please refresh and try again!');
                }
            }