I am using an Ajax call to post some template data to my HTML view with JQuery.
However, when I feed arrays to the following function, it only prints out one of the items in the array in the HTML/view.
The Ajax call:
request = $.ajax({
url: "/fans/follow",
type: "post", success:function(data){
var results = data;
$.each(results, function( index, value ) {
var template = '<li>'
+'<div class="row-fluid">'
+'<article class="span3">'
+'<a href="/fans/"'+value.fan_tag+'>'
+'<img src="https://graph.facebook.com/'+value.fbid+'/picture" alt="" height="40" width="40">'
+'</a>'
+'</article>'
+'<article class="span9 userDescp">'
+'<span>'
+'<a href="/fans/"'+value.fan_tag+'>'
+value.first_name+' '+value.last_name
+'</a>'
+'</span>'
+'</article>'
+'</div>'
+'</li>';
$('div#new_content').find('ul').html(template);
});
},
data: {'id': id} ,beforeSend: function(data){
console.log(data);
}
});
The HTML where it is supposed to print the template:
<div id="new_content">
<ul></ul>
</div>
Looking in the console, the array is being returned by ajax correctly, but it is not print all of the items, only the first one. I have also checked and the .each loop is going around as many times as there are items in the array, so that's not the issue. Anything I'm missing?