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...
]