Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5190
  • Last Modified:

Fullcalendar (JQuery Calendar) and JSON communication error

Hello,

I'm setting up an app using FullCalendar (http://arshaw.com/fullcalendar/) that will allow the user to see client scheduling information as well as schedule clients through a management interface.

I want to use a MySQL database to populate an array, and then pass that array in the form of a JSON feed to my HTML page.  Ideally, then, the client information would show up on the HTML page.  However, even though my JSON feed is being passed, there are no events on my FullCalendar.  

Example JSON feed being passed: [{"title":"Watson","start":"1333976400","end":"1333980000","allDay":false}]

I'm fairly new to these languages and I would not be at all surprised if this mistake turned out to be simple.

I would deeply appreciate any help or insight on having these events show up.  When I manually feed an array into FullCalendar, it does show the events, but so far my JSON feed has resulted in no information being displayed.

Thank you

For reference:
HTML:
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>Calendar</title>
		<script src="jquery-1.7.1.min.js" type="text/javascript" charset="utf-8"></script>
  		<script src="jquery-ui-1.8.17.custom.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel='stylesheet' type='text/css' href='fullcalendar.css' >
		<script type='text/javascript' src='jquery.js'></script>
		<script type='text/javascript' src='jquery.validate.js'></script>
		<script type='text/javascript' src='fullcalendar.js'></script>
	<script type="text/javascript">
		$(document).ready(function() {		
			$('#calendar').fullCalendar({
			    events: '/json-events.php'
			});		
	});
	</script>
	</head>
	<body>
		<div id="calendar"></div>
	</body>
</html>

Open in new window


PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>json-events</title>
</head>

<body>
	<?php 
		$start = $_GET['start'];
		$end = $_GET['end'];
		
		$hostname='localhost';
		$username='root';
		$password='password';
		$dbname='dbname';
		
		mysql_connect($hostname, $username, $password) or die("Unable to connect!");
		mysql_select_db($dbname);
	
		$result = mysql_query("select * from events");
		
		$event_array = array();
		
		while ($record = mysql_fetch_array($result)) {
		    $event_array[] = array(
		        'id' => $record['id'],
		        'title' => $record['title'],
		        'start' => $record['start_date'],
		        'end' => $record['end_date'],
		        'allDay' => $record['all_day']
		    );
		}
	echo json_encode($event_array);
	?>
	
</body>

</html>

Open in new window

0
deedub84
Asked:
deedub84
  • 3
1 Solution
 
Ray PaseurCommented:
Have you verified that the PHP script works correctly, returning a JSON string?  You should be able to test this by running the PHP script with a web browser.  I am curious about lines 11 and 12 of the PHP script.  These lines assume the existence of GET arguments that may not be present, and they assign variables that appear to be unused in the script.  That may be throwing a message or something that could bollix up the expected JSON return.
0
 
deedub84Author Commented:
When I run the php script in a browser I get back the JSON string--

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

which is what reflects what's in the sample database.  To my eye it appears correctly formatted.  Line 15 (events: '/json-events.php') doesn't seem to be finding the php script.  Am I missing something simple about referencing it's location (it is currently in the same directory as the HTML file?
0
 
deedub84Author Commented:
My PHP file was wrapped with HTML Tags, which made it look fine in a browser, but not work for the FullCalendar application.  Very rookie mistake indeed!
0
 
deedub84Author Commented:
Found my (very basic) error.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now