javascript - 来自 MySQL 的 JSON 提要有效,但不能超过 x 条记录

标签 javascript jquery fullcalendar

我正在尝试让 FullCalendar 与我的 MySQL 数据库一起工作。当我将查询限制为 25 条记录时,此方法有效。当我将我的 sql 查询更改为限制为 35 条记录时,Fullcalendar 不会添加任何事件并且基本上会继续加载。

我用 firebug 检查了 JSON 响应是什么,两次都是完整的。

一开始我以为是SQL查询的问题。数据库有 5000 多条记录,但 JSON 响应加载时间不到 200 毫秒。

我正在使用演示 json.html 文件进行测试。将在此处发布函数:

<script type='text/javascript'>
$(document).ready(function() {
    $('#calendar').fullCalendar({
        editable: true,
        events: "json-events.php",
        eventDrop: function(event, delta) {
            alert(event.title + ' was moved ' + delta + ' days\n' +
                '(should probably update your database)');
        },

        loading: function(bool) {
            if (bool) $('#loading').show();
            else $('#loading').hide();
        }
    });
});
</script>

这是我的 json-events.php

<?php
    $conn = mysql_connect("") or die ("Unable to connect to MySQL server.");

    $Exec = mysql_query("select Brand, date_in from planning ORDER BY date_in Desc Limit 35",$conn) or die(mysql_error());
    mysql_close();

    $events = array();

    while($row = mysql_fetch_assoc($Exec)) {
        $eventArray['title'] = $row['Brand'];
        $eventArray['start'] = $row['date_in'];
        $eventsArray['allDay'] = "";
        $events[] = $eventArray;
    }

    header('Content-type: application/json');

    echo json_encode($events);
?>

这是 JSON 响应:

[{"title":"Volkswagen Passat","start":"2011-04-28"},{"title":"Seat Alhambra","start":"2011-04-28"},{"title":"Ford Focus","start":"2011-04-20"},{"title":"BMW 5-Serie","start":"2011-04-20"},{"title":"Ford Mondeo","start":"2011-04-20"},{"title":"Volkswagen Caddy","start":"2011-04-20"},{"title":"Opel Zafira","start":"2011-04-18"},{"title":"Mazda 3","start":"2011-04-14"},{"title":"Opel Vectra","start":"2011-04-14"},{"title":"Peugeot 207","start":"2011-04-14"},{"title":"Volkswagen Golf","start":"2011-04-14"},{"title":"Volvo V90","start":"2011-04-14"},{"title":"Volvo V50","start":"2011-04-14"},{"title":"Volkswagen Polo","start":"2011-04-14"},{"title":"Volkswagen Golf","start":"2011-04-14"},{"title":"Ford Mondeo","start":"2011-04-14"},{"title":"Audi ","start":"2011-04-14"},{"title":"BMW 525i","start":"2011-04-14"},{"title":"Renault Laguna","start":"2011-04-14"},{"title":"Opel Astra","start":"2011-04-14"},{"title":"Seat Alambhra","start":"2011-04-14"},{"title":"Peugeot 307","start":"2011-04-13"},{"title":"Hyundai Atos","start":"2011-04-13"},{"title":"Citroen Xsara Picasso","start":"2011-04-13"},{"title":"Opel Astra","start":"2011-04-13"},{"title":"Volkswagen Golf","start":"2011-04-13"},{"title":"Peugeot 307","start":"2011-04-13"},{"title":"Volkswagen Passat","start":"2011-04-13"},{"title":null,"start":"2011-04-13"},{"title":"Citroen C1","start":"2011-04-13"},{"title":"Toyota Camry","start":"2011-04-13"},{"title":"Toyota Aygo","start":"2011-04-13"},{"title":"Nissan Qashqai","start":"2011-04-13"},{"title":"BMW 3 touring","start":"2011-04-12"},{"title":"Toyota Prius","start":"2011-04-12"}]

我尝试了所有我能想出的办法,我花了 5 个小时来完成这项工作。

有没有人知道如何使这项工作成功?

最佳答案

看起来错误在您的数据库中。

在您的 JSON 提要中,您有一个条目是

{"title":null,"start":"2011-04-13"}

null 可能是阻碍您前进的原因。

关于javascript - 来自 MySQL 的 JSON 提要有效,但不能超过 x 条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5676484/

相关文章:

fullcalendar - 如何通过代码触发点击 "today"按钮?

javascript - 用户对 JSDuck 文档的评论?

javascript - jQuery 下拉菜单仅在刷新其正常下拉菜单时风格化一次

javascript - 对嵌套对象的 javascript 数组进行排序

c# - 这段代码中的 IEventRepository 是什么? Resolver.resolve( ) 是做什么的?

laravel - FullCalendar - 删除事件中的点

javascript - 返回原始 div 时 jQuery FadeTo 不起作用

javascript - 组合框过滤后执行回调gridview

javascript - 为什么变量更改要延迟 x 毫秒才能生效?

javascript - 如何调整 Bootstrap Carousel 滑动延迟