根据来自html选择值的数据为FullCalendar提供json feed url

时间:2016-07-07 09:31:44

标签: javascript json fullcalendar

我在这里尝试自定义通常给出的json feed url。我想将输入数据作为GET请求添加到php文件events.php

剧本:

<script>
    $(document).ready(
        function eventcaller() {
            $('#calendar').fullCalendar(
            {
                events: 'events.php?room='+$( "#room_num" ).find( "option:selected" ).prop("value"),

                header: {
                    left: 'prev,next,today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                },
                defaultView: 'agendaWeek'
            });
        }
    );
</script>

events.php:

$room_num = $_GET['room_num'];
//I do queries and get an associative events array exactly the way fullcalendar likes it
$events=array();
echo json_encode($events);

HTML:

<select class="select form-control" id="room_num" name="room_num" onchange="eventcaller()">
    <option value="0">Select a room</option>
    <option value="1">1</option>
    // and so on.
</select>

我在控制台中收到以下错误:

Uncaught ReferenceError: eventcaller is not defined

指向我在onchange上提到的html select标签。

我不明白这里的错误是什么。如果有另一种方法来完成我的工作,我会非常高兴。提前致谢。

1 个答案:

答案 0 :(得分:0)

这解决了我使用PHP抓取POST变量dynamicValue的问题。

$("#calendar").fullCalendar({
    events: {
        url: "/myfeed",
        data: function() {
            return {
                dynamicValue: $("#dropdownList").val()
            };
        },
        type: "POST"
        }
    });
    $("#dropdownList").change(function () {
        $("#calendar").fullCalendar("refetchEvents");
    });   

之前曾问过这个问题,所以在这里 jquery fullcalendar send custom parameter and refresh calendar with JSON

相关问题