1

I'am trying to import an array from a class via ajax. When I call the file json It gives me a error 'there was an error while fetching events!'

I think that ajax asks for a json file but seems that file don't accepts objects and I don't know why.

Code: File: getDatasColaborador.php

<?php

header('Content-Type: application/json');

$datas = Calendario::getDatasByColaboradorIdKey(1);


$json = json_encode($datas);
echo $json;

File: Calendario.php

class Calendario{

public static function getDatasByColaboradorIdKey($colaborador_id){

   // $datas = array();
  /*  $colaborador = Colaborador::getColaboradorByIdKey($colaborador_id);
    $grupo_id = $colaborador->getGrupoId();

    require 'DBconfig.php';

    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    $conn->set_charset('utf8');

    $stmt = $conn->prepare("SELECT coordenador_id,data FROM calendario where colaborador_id=? and grupo_id=?");
    $stmt->bind_param('ss', $colaborador_id,$grupo_id);
    $stmt->execute();
    $stmt->bind_result($c1,$c2); */

    $datas = array( array("id"=>99, "title" => "aaaaa","start" => "2015-12-15"),array("id"=>98, "title" => "aaaaa","start" => "2015-12-22"));
    /*
    while($stmt->fetch()) {

        if($c1==null){
            array_push($datas,array("id"=> 99,"title" => $colaborador->getSigla(),"start" => $c2));
      }

    //   echo "<br>Id: ".$c1." - Name: ".$c2." - Email: ".$c3."- Password: ".$c4." - Ip: ".$c5." - Registed at: ".$c6." - Hasklink: ".$c7."<br>";         
    }*/
  //  $conn->close();

    return $datas; 

}

}

Jquery:

eventSources: [

    // your event source
    {
        url: '/gestor/Controller/getDatasColaborador.php',
        type: 'POST',            
        error: function() {
            alert('there was an error while fetching events!');
        },
        color: 'yellow',   // a non-ajax option
        textColor: 'black' // a non-ajax option
    }

    // any other sources...

]
Pedro
  • 89
  • 1
  • 11
  • If you change error functionality to be error: function(jqXHR) { alert(JSON.stringify(jqXHR, null, 4)); } what does the message say then? – smcd Dec 14 '15 at 20:27
  • Where is that eventSources array come from? How is that being used? And change `error: function() { alert('there was an error while fetching events!'); }` to `error: function(err) { alert('there was an error while fetching events!: '+ err); }` and tell us what the error message is – An0nC0d3r Dec 14 '15 at 20:27
  • First - post the request itself too, obviously there goes something wrong. Second - for debug, get a bit further information from the error - how? See here http://stackoverflow.com/a/14563181/1846918 – axel.michel Dec 14 '15 at 20:27
  • @smcd http://postimg.org/image/lq7fnkxsx/ – Pedro Dec 14 '15 at 20:40
  • @Pedro based on that image, something is bad with your PHP include path (or autoloader functionality) or file name is incorrect, /gestor/Model/Calendario.php is not able to be loaded? – smcd Dec 14 '15 at 20:48
  • @smcd I change the url to url: '../Model/Calendario.php'. Must be a relative path. Now works Thanks! – Pedro Dec 14 '15 at 20:55

0 Answers0