[英]Codeigniter - send controller data to view with json
您好我想將控制器數據發送到json查看,但我被阻止了。
我的模型(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;
}
我的控制器(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);
}
我的觀點(合同):
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');
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.