Advertisement
VladimirsBudkins

CI json from controller

Dec 29th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.36 KB | None | 0 0
  1. //controller
  2. public ajax_method(){
  3.     //fill with your data
  4.     $data = array('success'=>true);
  5.     if($this->input->is_ajax_request()){
  6.         $this->output
  7.                  ->set_content_type('application/json')
  8.                  ->set_output(json_encode($data));
  9.     }else{
  10.         //for example show_404()
  11.     }
  12.  
  13. }
  14.  
  15. //jq script
  16. $.getJSON("url",function(data){
  17.     console.log(data);
  18. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement