Skip to content

Strange AJAX error in Magento 2.4

I developed a module for Magento 2.4 that consumes an API with multiple endpoints and one of them is returning the response as JSON.

If I create an AJAX call, the response I will get on the desktop version is a valid JSON, but on mobile, the same AJAX call gives an error (SyntaxError: JSON Parse error: Unrecognized token ‘<‘).

If I remove “dataType: JSON” and parse the returned AJAX response as a string on mobile, I will see that it contains a short tag (script … pub/errors/report.php … ).

What could be the issue behind this? I can’t parse the response on mobile as JSON, but everything works as expected on the desktop version.

Thank you!