0
Code:
$(document).ready(function (){
var products = "";
var url = "https://cdn.rawgit.com/LucasRuy/1d4a5d45e2ea204d712d0b324af28bab/raw/342e0e9277be486102543c7f50ef5fcf193234b6/potions.json";
$.ajax({
url: url,
dataType: "json",
success: function (response) {
if(response.erro) {
$("h2").html(response.erro);
}else {
for(var i = 0; i < response.data.length; i++) {
products += "<ul class='ranking'>";
products += "<li class='list'><img class='image' src=" + response.data[i].image + "></li>";
products += "<li class='list'><p class='name'>" + response.data[i].name + "</p></li>";
products += "<li class='list'><p class='price'>" + response.data[i].price + "</p></li>";
products += "</ul>";
}
$('.box-products').html(products);
}
}
});
});
Error:
script.js:12 Uncaught Typeerror: Cannot read Property 'lenght' of Undefined
Given that the only use of
length
is inresponse.data.length
, by the error message, the attributedata
does not exist inresponse
. There should be?– Woss
Apparently, your [Answer.data] does not exist. It would be interesting to put a validation before the for
– Lucas