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
Share:
14,304

Related videos on Youtube

RouthMedia
Author by

RouthMedia

Web Developer amongst other things.

Updated on June 04, 2022

Comments

  • RouthMedia
    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
      Naren Verma over 5 years
      Can you share your HTML code or make a jsfiddle link?
    • skechav
      skechav about 5 years
      Setting $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
    user-9725874 over 5 years
    That error has something to do with this: php.net/manual/en/function.ob-gzhandler.php
  • RouthMedia
    RouthMedia over 5 years
    I will try this. Is the config file the codeigniter config file? Thanks
  • RouthMedia
    RouthMedia over 5 years
    Can the zlib.output_compression=On be done via htaccess per domain?
  • RouthMedia
    RouthMedia over 5 years
    I 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
    RouthMedia over 5 years
    I 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
    RouthMedia over 5 years
    I 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!