Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
FullCalendar.io events can't be loaded through PHP, FullCalendar tries to parse the contents of the PHP script instead of its output

I am trying to load some events from a MySQL Database into a calendar from FullCalendar. For that, I have created a connection to the Database in a PHP file for getting the data and outputting it as a JSON.

The connection is working fine and when executing the PHP file in a terminal, I get a JSON with the correct data.

But when trying to get the data through the FullCalendar API, it doesn't work. In the browser console I get the Warning 'Failure parsing JSON' from FullCalendar and when looking at the response it tried to parse, it's just the php code itself, not its output.

So I copied the correct output I got from executing the PHP file in a normal terminal and replaced the PHP code in the PHP file with it, and then the parsing was successful, so apparently FullCalendar just tries to parse the contents of the PHP file instead of its output.

What is the reason for that? How do I correctly transfer the output from the PHP file to the FullCalendar API?

JavaScript in index.html:

<script>

        document.addEventListener('DOMContentLoaded', function() {
            var calendarEl = document.getElementById('calendar');
            
            var calendar = new FullCalendar.Calendar(calendarEl, {
            initialDate: '2021-09-12',
            events: "get-events.php",
            });
            
            calendar.render();
        });

</script>

get-events.php

 <?php
    $servername = "127.0.0.1";
    $username = "root";
    $password = "";
    $dbname = "database";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);

    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 

    $sql = "SELECT Title as title, Start as start, End as end FROM event_table";
    $result = mysqli_query($conn, $sql); 
    $myArray = array();
    if ($result -> num_rows > 0) {
        while($row = $result -> fetch_assoc()) {
            $myArray[] = $row;
        }
    } 
    print json_encode($myArray);
?> 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The solution was simple, it had nothing to do with the PHP or JavaScript Code, my server environment just wasn't correctly configured (especially PHP), so the PHP code couldn't be executed.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!