Skip to content

Instantly share code, notes, and snippets.

@ntung
Forked from olivierobert/CI Detect Ajax
Created May 5, 2017 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntung/14bcdf5326dc2a694956335ea75e1b47 to your computer and use it in GitHub Desktop.
Save ntung/14bcdf5326dc2a694956335ea75e1b47 to your computer and use it in GitHub Desktop.
Code Igniter // Detect and return AJAX / JSON response
/** Within the controller method **/
// If this is an ajax request, then return a JSON string
if ( $this->input->is_ajax_request() ):
$this->output->set_content_type('application/json');
$this->output->set_output( json_encode($data) );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment