I need a help with javascript. I'm trying to show in my index.html the data I'm consuming from a json. However when opening the index and waiting for the document to be loaded the items come with undefined.
$(document).ready(function () {
var products = "";
var url = "https://api.myjson.com/bins/10p600";
$.ajax({
url: url,
dataType: "json",
success: function (response) {
if(response[0].erro) {
$("h2").html(response[0].erro);
}else {
for(var i = 0; i < response.length; i++) {
products += "<div>";
products += "<div>" + response[i].imageName + "</div>";
products += "<h4>" + response[i].name + "</h4>";
products += "<p>" + response[i].price + "</p>";
products += "<p>" + response[i].paymentConditions + "</p>";
products += "</div>";
}
$("#myproducts").html(products);
}
}
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Teste Front-End</title>
</head>
<body>
<div id="myproducts"></div>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script><scripttype="text/javascript" src="teste.js"></script>
</body>
</html>