NDBoost
NDBoost

Reputation: 10634

How To Make CodeIgniter's profiler and ajax requests play nice

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);
}

question:

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

Answers (3)

Ian Hoar
Ian Hoar

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

Robin Castlin
Robin Castlin

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

Nish
Nish

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

Related Questions