Link to home
Start Free TrialLog in
Avatar of deedub84
deedub84Flag for United States of America

asked on

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

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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.
Avatar of deedub84

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of deedub84
deedub84
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Found my (very basic) error.