0
    $(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!

2
  • 1
    try setting dataType:'json in AJAX. Also plugin has option to use URL as event source and will do the AJAX for you Commented Dec 12, 2012 at 22:47
  • Using a URL for the events was actually the solution here. There is a very specific format that the Arshaw Fullcalendar is needing that I will be posting on this thread. Commented Dec 12, 2012 at 23:08

3 Answers 3

3

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' 
    ......
Sign up to request clarification or add additional context in comments.

Comments

1

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

2 Comments

if you provide dataType:'JSON' jQuery will parse it automatically
@popnoodles Yes I know. They both will do the same thing
-1
    $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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.