WChris
WChris

Reputation: 71

FullCalendar. Getting events to appear on calendar using JSON script

I am having difficulty getting events into my FULLCALENDAR when reading events created using a JSON encode script. The script that is generating the JSON is as follows, It seems to be working ok as it is generating the json string expected

get_events.php:

            include("../../../../databaseconnect.php");

            $sql = 

            "
            SELECT id, title, description, start
            FROM calendar
            WHERE agentid='$agentid'

            ";
            $result = mysqli_query($conn, $sql);
            if (mysqli_num_rows($result) > 0) 
            {
                    $rows = array();

                    while($row = mysqli_fetch_assoc($result))                                    
                    {                           

                         $rows[] = $row;
                    }   
            } 

        echo json_encode($rows);

The get_events.php script is generating this JSON string below-- as expected:

            [
                {
                    "id": "21",
                    "title": "My Event 2",
                    "description": "Electricity",
                    "start": "2017-03-02 00:00:00"
                },
                {
                    "id": "22",
                    "title": "My Event 3",
                    "description": "Gas",
                    "start": "2017-03-07 00:00:00"
                }
            ]

However, all I am seeing is a blank calendar. I have tested the FULLCALENDAR scripting below:-

                //Tested this..         
                events: "http://www.example.com/PropertyIndex/applicant_calendar/fullcalendar/demos/get_events.php",


                //Tested this..
                events: 
                {
                    url: 'http://www.example.com/PropertyIndex/applicant_calendar/fullcalendar/demos/get_events.php',
                    error: function() 
                    {
                        $('#script-warning').show();
                    }
                },

No luck. Just a blank calendar. However when I test inserting the same events directly (as below) the events appear as expected.

            events: [

                        {


                            "id": "21",
                            "title": "My Event 2",
                            "description": "Electricity",
                            "start": "2017-03-02 00:00:00"
                        },
                        {
                            "id": "22",
                            "title": "My Event 3",
                            "description": "Gas",
                            "start": "2017-03-07 00:00:00"
                        }
                    ]

Would welcome any ideas on this. Thank you

Upvotes: 0

Views: 76

Answers (1)

WChris
WChris

Reputation: 71

Problem solved. Set the URL to relative rather than the full URL. Hope it might help someone else one day.

        events: 
        {
            url: 'get_events.php',
            error: function() 
            {
                $('#script-warning').show();
            }
        },

Upvotes: 0

Related Questions