dongqiang4819 2013-09-26 18:51
浏览 64

我已经用php mysqli集成实现了fullcalendar,但是无法获取页面来呈现存储在数据库中的事件

I have managed to get events to add to the database by calling addevents.php and passing variables via ajax to the php script. I have events.php that SELECTS everything from the table and passes it back to the calendar (default.html) as a string. However the calendar will not populate.

events.php
<?php
// List of events
$json = array();

// connection to the database
$mysqli = new mysqli("localhost", "root", null, "fullcalendar");

//check connection
if (mysqli_connect_errno()) {
    printf("Connect failed: %s
", mysqli_connect_error());
    exit();
}

//fetches and sends data in string
$result = $mysqli->query("SELECT * FROM calendar_data ORDER BY id");
$display = $result->fetch_array(MYSQLI_ASSOC);
echo json_encode($display);
?>

default.html
<!DOCTYPE html>
<html>
<head>
    <link href='css/fullcalendar.css' rel='stylesheet' />
    <script src='http://code.jquery.com/jquery-1.9.1.js'></script>
    <script src='http://code.jquery.com/ui/1.10.3/jquery-ui.js'></script>
    <script src='js/fullcalendar.min.js'></script>
    <script>
        $(document).ready(function() {
            var date = new Date();
            var d = date.getDate();
            var m = date.getMonth();
            var y = date.getFullYear();
            var calendar = $('#calendar').fullCalendar({
                editable: true,
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                },
                events: "http://localhost:80/fullcalendar/events.php",
                // Convert the allDay from string to boolean
                eventRender: function(event, element, view) {
                    if (event.allDay === 'true') {
                        event.allDay = true;
                    } else {
                    event.allDay = false;
                    }
                },
                selectable: true,
                selectHelper: true,
                select: function(start, end, allDay) {
                    var title = prompt('Event Title:');
                    if (title) {
                        start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
                        end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");
                        $.ajax({
                            url: 'http://localhost:80/fullcalendar/add_events.php',
                            data: 'title='+ title+'&start='+ start +'&end='+ end ,
                            type: "POST",
                            success: function(json) {
                            alert('Added Successfully');
                            }
                        });
                        calendar.fullCalendar('renderEvent',
                        {
                            title: title,
                            start: start,
                            end: end,
                            allDay: allDay
                        },
                            true // make the event "stick"
                        );
                    }
                    calendar.fullCalendar('unselect');
                },
                editable: true,
                eventDrop: function(event, delta) {
                    start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
                    end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
                    $.ajax({
                        url: 'http://localhost:80/fullcalendar/update_events.php',
                        data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id ,
                        type: "POST",
                        success: function(json) {
                            alert("Updated Successfully");
                        }
                    });
                },
                eventResize: function(event) {
                    start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
                    end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
                    $.ajax({
                        url: 'http://localhost:80/fullcalendar/update_events.php',
                        data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id ,
                        type: "POST",
                        success: function(json) {
                            alert("Updated Successfully");
                        }
                    });
                }
            });  
        });
    </script>
    <style>
        body {
            margin-top: 40px;
            text-align: center;
            font-size: 14px;
            font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
        }
        #calendar {
            width: 720px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <div id='calendar'></div>
</body>
</html>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?