0

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

in the Ajax response

$.get(url, function(data) {
$('#load-more-loader').hide();
$('#load-more-product').show();
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) {
$('.products.list.items.product-items').append(value);
$("form[data-role='tocart-form']").catalogAddToCart();
});
$('#load-more').hide();
if (typeof nxtUrl === "undefined") {
$('#load-more-product').html('<em>No More product in this Category.</em>');
} else {
$('.next').attr('href', nxtUrl);
}
});

1 Answer 1

0

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 '<'.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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