Reputation: 10634
from what i can tell, ajax hates when CIs profiler is enabled as it injects html into the view()
method at the end.Which messes with the success:
callback on $.ajax()
.
My thoughts were, rather than defining $this->output->enable_profiler(false);
on all of my methods that are used for ajax calls, i could use the following code in a hook or core controller that extends CI_Controller.. or somewhere else, just not sure where to put it.
<?php
if( $this->input->is_ajax_request() ){
$this->output->enable_profiler(false);
}
where can i put the following code, to make CI disable the profiler if its enabled just for ajax requests that would take effect globally across all areas. If there is a better solution of course, let me know. But Google reveals nothing.
Upvotes: 3
Views: 3462
Reputation: 1184
I know this is answered, but I used this instead of passing a field in MY_Controller.php
if($this->input->is_ajax_request()) {
$this->output->enable_profiler(false);
} else {
$this->output->enable_profiler(true);
}
Tested in Chrome and only needed on my dev box anyway.
Upvotes: 1
Reputation: 10996
Couldn't you simply instead of
echo json_encode($json);
do a
die(json_encode($json));
? Leaves the system no chance to print out profiler.
Upvotes: 0
Reputation: 2356
Please extend the core controller and in the constructor check for an special post variable name in the post array and disable the profiler.
class MY_Controller extends CI_Controller {
function __construct()
{
parent::__construct();
if(isset($_POST['is_ajax_request'])
$this->output->enable_profiler(false);
}
}
When sending ajax request send a field is_ajax_request to disable profiler.
Upvotes: 4