0
你好我想發送控制器數據與json查看,但我是一個封鎖。Codeigniter - 發送控制器數據與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);
}
我的觀點(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');
}
});
}
你爲什麼在視圖裏寫一個函數?你爲什麼不使用模板視圖系統?我認爲你在這裏犯了很多錯誤。如果你的模板是這樣的,當你檢查你的頁面的html時,是否存在$ .ajax函數? – Chococroc
您的代碼易受SQL注入攻擊。 –