3
I’m getting via JSON
one array
, I walk him with the .each()
of JQUERY
, so I mount my html, and I put it in a div
within my page. All this said is done:
$.getJSON('http://localhost:8000/produtos', function(data) {
$('#todosProdutos').html('');
$.each(data, function (key, item) {
var ANTIGO = $('#todosProdutos').html();
var html = ANTIGO + '<div class="item">'
+'<div class="product">'
+'<div class="flip-container">'
+'<div class="flipper">'
+'<div class="front">'
+'<a href="detail">'
+'<img src="img/product1.jpg" alt="" class="img-responsive">'
+'</a>'
+'</div>'
+'<div class="back">'
+'<a href="detail">'
+'<img src="img/product1_2.jpg" alt="" class="img-responsive">'
+'</a>'
+'</div>'
+'</div>'
+'</div>'
+'<a href="detail" class="invisible">'
+'<img src="img/product1.jpg" alt="" class="img-responsive">'
+'</a>'
+'<div class="text">'
+'<h3><a href="detail">Fur coat with very but very very long name</a></h3>'
+'<p class="price">$143.00</p>'
+'</div>'
+'<!-- /.text -->'
+'</div>'
+'<!-- /.product -->'
+'</div>';
});
console.log(html);
$('#todosProdutos').html(html);
console.log(data);
});
When I gave the console.log(html)
says that the variable not this definition, this I know the problem, is due to the scope of variable, but I tried to put the .html()
within the .each()
and I also did not succeed, my html appears, but does not put on the page.
Where can my mistake be? And What better way to do this ?
Man console.log(data)
:
So @Renanrodrigues, is coming date values that are 4 items within the
array
and thehtml
has values? on the page does not appear at least html with the fixed information you have placed?– novic
What happens and that I am doing a test to know if it will put the items on the screen, with fixed values, I know that is getting the data correctly now the problem is on the screen.
– Renan Rodrigues
I do not know well, I made an edit, your html was wrong! take a look see if it appears as you said yourself 4 fixed items (because it will run 4 times if it is right).
– novic