2017-05-27 47 views
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'); 
     } 
    }); 
} 
+0

你为什么在视图里写一个函数?你为什么不使用模板视图系统?我认为你在这里犯了很多错误。如果你的模板是这样的,当你检查你的页面的html时,是否存在$ .ajax函数? – Chococroc

+0

您的代码易受SQL注入攻击。 –

回答