Hello I'd like to send controller data to view with json but I'm a blocked.
My model (contrat_model) :
function presence($id_personnel,$debut,$fin){
$presence='';
$query="select statut from presence where id_employee=$id_employee and (work_date>=$debut and work_date<$fin)";
$presence=$this->db->query($query);
return $presence;
}
My controller (contrat_controller) :
public function presence($id_employee,$debut,$fin){
$presence=$this->contrat_model->presence($id_employee,$debut,$fin);
$i=0;
$all=0;
foreach ($presence as $row){
$statut=$row;
$all++;
if($statut=="green"){
$i++;
}
}
$data=array("i"=>$i, "all"=>$all);
echo json_encode($data);
}
My view (contrat) :
function afficher(id_personnel,debut,fin)
{
$.ajax({
url : "<?php echo site_url('Contrat_controller/presence')?>/"+id_personnel+"/"+debut+"/"+fin,
type: "GET",
dataType: "JSON",
success: function(data)
{
alert(data.i);
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Erreur d\'affichage du graphe');
}
});
}