Magento2 Error Uncaught SyntaxError: Unexpected token < in JSON at position 0

in the Ajax response

$.get(url, function(data) {
var myArray = JSON.parse(data);

var result = $(myArray.categoryProducts).find('.item.product.product-item');
var nxtUrl = $(myArray.categoryProducts).find('.next').attr('href');
$.each(result, function(index, value) {
if (typeof nxtUrl === "undefined") {
$('#load-more-product').html('<em>No More product in this Category.</em>');
} else {
$('.next').attr('href', nxtUrl);

1 Answer 1


Open the request in the network tab of your browser's dev tools. There you will see the response from the server. Since jQuery Ajax expects json in the result, it can in no way start with an '<'. My guess is that in the response there is a 404 page, which is in HTML which indeed starts with an '<'.

  • I think the issue is related to page starting with <!Doc type html>. If that is then how can I solve it
    – Arjun
    Commented May 24, 2022 at 6:03
  • I'm not sure, maybe you should also provide the controller code.
    – Zankar
    Commented May 24, 2022 at 6:35

Your Answer

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

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