AJAX returning ERR_CONTENT_DECODING_FAILED 200 using Codeigniter
14,304
Add this code in your config file:
$config['compress_output'] = FALSE;
Enable gzip compression in php.ini:
zlib.output_compression=On
Related videos on Youtube
Comments
-
RouthMedia almost 2 years
I have two AJAX requests on the same page sending data to a Codeigniter framework.
One sends a form of input fields containing shop opening hours. This functions correctly.
$(".hour-field").blur(function(){ $.ajax({ url:'<?php echo base_url(); ?>businesses/updatehours', type: 'POST', dataType: 'json', data: $("#edit-hours").serialize(), success: function(data){ console.log(data); }, error: function(data){ console.log(data) } }); });
The other sends data from a radio input form. This one returns ERR_CONTENT_DECODING_FAILED 200
$(".image-selector").click(function(e){ $.ajax({ url:'<?php echo base_url(); ?>businesses/selectimage', type: 'POST', dataType: 'json', data: $("#select-image").serialize(), success: function(data){ console.log(data); }, error: function(data){ console.log(data) } }); });
I have tried removing the 'dataType' without success.
There is seemingly no difference between the two but one is not working.
-
Naren Verma over 5 yearsCan you share your HTML code or make a jsfiddle link?
-
skechav about 5 yearsSetting $config['compress_output'] = FALSE will do the (dirty) job but you should also check if you are passing an empty result object or array to json_encode() function on your controller, or model ..
-
-
user-9725874 over 5 yearsThat error has something to do with this: php.net/manual/en/function.ob-gzhandler.php
-
RouthMedia over 5 yearsI will try this. Is the config file the codeigniter config file? Thanks
-
RouthMedia over 5 yearsCan the zlib.output_compression=On be done via htaccess per domain?
-
RouthMedia over 5 yearsI haven't managed to put anything in my .htaccess file, but it seems to be working ok. Perhaps I have some settings within plesk.
-
RouthMedia over 5 yearsI now have the strange problem that the first click on the radio field doesn't submit the form data with the ajax request so my php script throws an error as the form variable doesn't exist. Subsequent presses do work.
-
RouthMedia over 5 yearsI realised that I am clicking on images within the radio field's label, therefore I was not sending the correct data with the ajax submission. I have now fixed the problem. Thanks for your help!