How to get FullCalendar to display information from my JSON channel?

I configure the application using FullCalendar ( http://arshaw.com/fullcalendar/ ), which will allow the user to see client scheduling information as well as client schedules through the management interface.

I want to use a MySQL database to populate an array, and then pass that array as a JSON channel to FullCalendar on the HTML page. Ideally, customer information will be displayed on an HTML page. However, although my JSON channel is being transmitted, there are no events on my FullCalendar.

JSON pass example:

[{"title":"Watson","start":"1333976400","end":"1333980000","allDay":false}] 

I am new to these languages ​​and I won’t be surprised if this error turns out to be simple.

I would deeply appreciate any help or understanding that these events will appear. When I manually load an array into FullCalendar, it shows events, but so far my JSON channel has not displayed any information.

thanks

For reference: HTML:

  $(document).ready(function() { $('#calendar').fullCalendar({ events: '/json-events.php' }); }); 

PHP:

  while ($record = mysql_fetch_array($result)) { $event_array[] = array( 'id' => $record['id'], 'title' => $record['title'], 'start' => $record['start_date'], 'end' => $record['end_date'], 'allDay' => false ); } echo json_encode($event_array); 
+6
source share
3 answers

So the problem for those following me was that there were header tags and HTML tags in my PHP file. I am a PHP noob, so I did not know that this would not work. In order for FullCalendar to display the JSON feed, it must have only PHP code, not HTML. JSONLint.com was invaluable in understanding this.

+7
source

I set up a quick example and had no problems getting this to work:

PHP:

 <?php $record[0]["title"]="Test 1"; $record[1]["title"]="Test 2"; $record[2]["title"]="Test 3"; $record[0]["start_date"]="1333976400"; $record[1]["start_date"]="1333976401"; $record[2]["start_date"]="1333976402"; $record[0]["end_date"]="1333980000"; $record[1]["end_date"]="1333980001"; $record[2]["end_date"]="1333980002"; $record[0]["id"]="1"; $record[1]["id"]="2"; $record[2]["id"]="3"; for ($i=0; $i<3; $i++) { $event_array[] = array( 'id' => $record[$i]['id'], 'title' => $record[$i]['title'], 'start' => $record[$i]['start_date'], 'end' => $record[$i]['end_date'], 'allDay' => false ); } echo json_encode($event_array); exit; ?> 

HTML:

 events: '/events.php' 

Example output from a PHP script:

 [{"id":"1","title":"Test 1","start":"1333976400","end":"1333980000","allDay":false},{"id":"2","title":"Test 2","start":"1333976401","end":"1333980001","allDay":false},{"id":"3","title":"Test 3","start":"1333976402","end":"1333980002","allDay":false}] 

So, given that the above works for me, and it really is no different from what you have above, you may need to check if the PHP script is being called correctly. Check the Javascript console in Mozilla Firefox or Google Chrome to see if there are any errors that occur when trying to download Fullcalendar. Check your web server access logs / error logs for any mention of the php script.

+5
source
 events: '/json-events.php' 

should be either

 events: './json-events.php' 

or

 events: 'json-events.php' 

Let me know if this helps ...

EDIT

I also noticed that in the Json that you get there is no identifier in the string. Maybe something happens between the name of your identifier in DB compared to the name you use in the array. Check this out and see what happens, because this is one of the properties needed to send an event.

EDIT

Try removing [] from $ event_array [] and see what happens ... If this does not work, I crashed ... sorry

+1
source

Source: https://habr.com/ru/post/912801/


All Articles