2

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.

2
  • Can you share your HTML code or make a jsfiddle link? Sep 23, 2018 at 10:11
  • 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 ..
    – skechav
    Feb 22, 2019 at 23:16

1 Answer 1

12

Add this code in your config file:

$config['compress_output'] = FALSE;

Enable gzip compression in php.ini:

zlib.output_compression=On
6
  • That error has something to do with this: php.net/manual/en/function.ob-gzhandler.php Sep 24, 2018 at 2:41
  • I will try this. Is the config file the codeigniter config file? Thanks
    – RouthMedia
    Sep 24, 2018 at 5:18
  • Can the zlib.output_compression=On be done via htaccess per domain?
    – RouthMedia
    Sep 24, 2018 at 9:15
  • 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
    Sep 24, 2018 at 19:34
  • 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
    Sep 24, 2018 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.