Welcome Guest, Not a member yet? Register   Sign In
Output.php with compress_output = true, always calls ob_start('ob_gzhandler') causing warning with ajax
#1

[eluser]Mitchell[/eluser]
Using CI with jquery/ajax, I encountered an error that took me quite a while to track down. This only occurs with $config['compress_output'] = true.

Here's the sequence:

1. Make ajax request with datatype = json to controller function

2. Controller function ends with: echo json_encode($data) in order to return data to javascript/jquery.

3. If $config['compress_output'] == true, then in file Output.php, line 287, ob_start('ob_gzhandler') is executed. If this line is executed, then the classic warning: "Cannot modify header information - Headers already sent" occurs. The error message refers back to the line in step 2: echo json_encode($data). In this particular situation, the variable $output is empty because the controller function is not loading a view.

4. If I either comment out the line ob_start('ob_gzhandler') or set compress_output = false, then the warning does not occur.

5. My guess for a fix would be to add the condition (&& $output != '') before calling ob_start().

6. Current work around is to add 2 lines before the end of the controller function:
global $CFG;
$CFG->config['compress_output'] = FALSE;




Theme © iAndrew 2016 - Forum software by © MyBB