0

I'm getting that silly error when calling an ajax request, and when I open the URL of the Ajax in the browser, I get the same error.

enter image description here

enter image description here

I've been in this for 2 months. I removed my .htaccess and nothing changed. This is happening only on local environment, not on production.

I tried adding

zlib.output_compression = On;

to my php.ini but did not change anything.

I'm using Opencart 2.2.0.0 | PHP 5.6 | Ubuntu LAMP

UPDATE 1

This is the code called via ajax:-

enter image description here

if I add a print_r($data); it prints the data array, but the issue occurs when it tries to return the rendered content of the view file, I tried to create another view file but got the same response.

UPDATE 2

Here is the request from devTools > network tab:-

enter image description here

and the response tab is empty, no response it returned.

UPDATE 3

enter image description here

Hazem Taha
  • 1,022
  • 4
  • 18
  • 29
  • 1
    Have you tried all the suggestions here ~ [Error 330 (net::ERR_CONTENT_DECODING_FAILED):](https://stackoverflow.com/questions/14039804/error-330-neterr-content-decoding-failed)? Remember, if you make changes to `php.ini`, you need to restart the HTTP server – Phil Oct 15 '18 at 05:56
  • put error_reporting in starting of your page https://stackoverflow.com/a/37036144/5700401 – Abhijit Jagtap Oct 15 '18 at 05:57
  • Tried them all now, but did not work :( – Hazem Taha Oct 15 '18 at 06:21
  • Here I give you a [Present](https://github.com/ArtisticPhoenix/MISC/blob/master/AjaxWrapper/AjaxWrapper.php) This is a AjaxWrapper class in PHP that will trap any output that happens inside of it, and most errors. So that your JSON is still valid even if you have PHP errors. `I've been in this for 2 months` Hope you haven't been stuck on this for that long. Also remove these `?>` from pure PHP files. – ArtisticPhoenix Oct 15 '18 at 06:24
  • @ArtisticPhoenix thanks for help. I don't think it is related to Ajax as I get the same response when accessing the URL from the browser normally and getting the response in the screenshot above, what do you think ? – Hazem Taha Oct 15 '18 at 07:11
  • 1
    `accessing the URL from the browser normally` an AJAX request is a HTTP request, a browser is a HTTP request. The server dosn't know the difference. – ArtisticPhoenix Oct 15 '18 at 07:15
  • can you please check the (UPDATE 1 ) above if it might help. – Hazem Taha Oct 15 '18 at 07:53

2 Answers2

1

The "<" often indicates that you are trying to json-decode html. Have you checked devtools and seen what is actually returned by the server?

I've seen this myself when requests for json-data has either returned html-formatted error messages or when the requesting user has not been logged in and the Ajax call has (erroneously) redirected to a login screen.

Dag Sondre Hansen
  • 2,259
  • 17
  • 21
  • Sounds like you are still not getting valid json-data, but based on the scarce info I have it's almost impossible to say why. Check for php-notifications, warnings etc which surely is muted in the production environment but may be present in your development setup. You should see this quite easily in devtools. – Dag Sondre Hansen Oct 15 '18 at 07:21
  • No json data used in the page, can you please check the (UPDATE 1 ) above if it might help. – Hazem Taha Oct 15 '18 at 07:53
  • @HazemTaha: Can you show the Response from the call from Chrome DevTools? (If you are not familiar with this: open DevTools, select Network tab, find and select the correct http-request and copy the text from the Respone-tab). – Dag Sondre Hansen Oct 15 '18 at 08:12
  • @HazemTaha: the last update shows the request, not the response (which is shown in the Resonse-tab). – Dag Sondre Hansen Oct 15 '18 at 16:20
  • The response is empty, please find the UPDATE 3 screenshot. – Hazem Taha Oct 16 '18 at 05:54
  • If the response is consistently empty I'm fresh out of suggestions to what may cause the problem. My approach would be to set a breakpoint on line 38 and single step through the code to see what is happening. – Dag Sondre Hansen Oct 16 '18 at 06:34
1

In my experience this error comes up when there is a php error and compression is turned on. Go to Admin > System > Settings and then to the Server tab and set Output Compression Level to 0. Also make sure Display Errors is set to ON.

Now inspect the response from your Ajax call and instead of a decoding error you will be able to see the actual error that's being reported.

Also remember if it's a FATAL error the script can crash before it even gets a chance to initialize the custom error handler and the the only way to get data about these will be in the webserver error logs.

billynoah
  • 17,021
  • 9
  • 67
  • 90
  • 1
    Thanks so much!! I tried disabling output compression from php.ini, but it seems like it wasn't taking effect, you saved me much much time. Thanks alot again. – Hazem Taha Oct 17 '18 at 10:53