$(document).ready(function () {
output = "";
$.ajax({
url: 'getevents.php',
data: { ufirstname: 'ufirstname' },
type: 'post',
success: function (output) {
alert(output);
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
editable: true,
events: output
});
}
});
});
I have code like this and if I copy the text verbatim out of my alert box and replace
events: output
with
events: [{ id: 1, title: 'Birthday', start: new Date(1355011200*1000), end: new Date(1355011200*1000), allDay: true, url: 'http://www.yahoo.com/'},{ id: 2, title: 'Birthday Hangover', start: new Date(1355097600*1000), end: new Date(1355097600*1000), allDay: false, url: 'http://www.yahoo.com'},{ id: 3, title: 'Sepotomus Maximus Christmas', start: new Date(1356393600*1000), end: new Date(1356393600*1000), allDay: false, url: 'http://www.yahoo.com/'},]
Everything works just fine. What can I do to fix this problem? I though that using events: output
would place the text in that location but it does not seem to be working.
Thank you all kindly in advance for any comments or answers!
Since you haven't given us much information, i'm going to take a shot in the dark and say that the browser is interpreting the json as text. So add a dataType
property to the ajax call so that jQuery can parse the return as json.
$.ajax({
url: 'getevents.php',
data: { ufirstname: 'ufirstname' },
type: 'post',
dataType: 'json'
......
If you are getting that string in your alertbox.. You need to use JSON.parse() to parse the string into a javascript Object
change
events: output
to
events: JSON.parse(output)
According to the documentation
An "event source" is anything that provides FullCalendar with data about events. It can be a simple array, an event-generating function that you define, a URL to a json feed, or a Google Calendar feed.
Since version 1.5, Event Objects can have "options" associated with them. However, before you can start specifying options, you must write an Event Object in its extended form. It must be a traditional JavaScript object with properties.
Also your json string has an extra comma at the end
$year = date('Y');
$month = date('m');
echo json_encode(array(
array(
'id' => 111,
'title' => "Event1",
'start' => "$year-$month-10",
'url' => "http://yahoo.com/"
),
array(
'id' => 222,
'title' => "Event2",
'start' => "$year-$month-20",
'end' => "$year-$month-22",
'url' => "http://yahoo.com/"
)
));
The program actually wants this very specific format of json_encode or it does not work. I only figured this out by reading through all of these replies.