I want done loop for response (three times loop), and i want append they in a .list but it don’t work for me, (response have value in alert). what do i do?
$.ajax({
type: "POST",
dataType: "json",
url: 'url',
data: val,
cache: false,
success: function (response) {
var $unitses = $('<div class="list"></div>');
$.each(response, function (index, value){
$('.list', $unitses).append('value.name');
//alert(response);
});
$('#rname').append($unitses); // This don't work append
},
"error": function (x, y, z) {
alert("An error has occured:\n" + x + "\n" + y + "\n" + z);
}
});
$('.list', $unitses)will search for an element with classlistinside$unitses, but this element does not contain any other elements.You want
$unitses.append(value.name);instead (note, no quotes).This will put all
value.namevalues inside that element, one after each other, which is probably not really readable. If you provide an example forresponseand what you expect as output, we can provide better help.