简体   繁体   中英

JSON feed from MySQL works, but not with more than x records

I'm trying to get FullCalendar to work with my MySQL db. This works when I limit my query to 25 records. When I change my sql query to limit to, lets say 35 records, Fullcalendar will not add any event and basically keeps loading.

I checked with firebug what the JSON response was and in both times it's complete.

At first I thought the problem was the SQL query. The DB is 5000+ records long but the JSON response is loading in less then 200ms.

I'm using the demo json.html file for testing. will post the function here:

<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>

This is my 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);
?>

This is the JSON response:

[{"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"}]

I tried everything I could come up with, I've spend 5 hours trying to make this work.

Is there anyone who has any idea how to make this work?

It looks like the error is in your database.

In your JSON feed you have an entry that is

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

That null is probably what is holding you up.

I think i found part of the problem, special characters in the name turn up as NULLS in the JSON output, names like Renault Mégane. so i changed the charset to:

<meta http-equiv="Content-Type" content="text/html; charset="Latin-1"></meta>

I also changed the JSON and added:

mysql_set_charset("utf8");

The're still some minor issues, but it works! thanks for your help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM