Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

276
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda