How would I go about iterating over the following foreach with a delay between each item and a fadeIn on each?
I’m not sure that .append() is the best function to use as what I’m trying to achieve is to load a templated div with the class #fan for each person in the json, which looks like:
[{"first_name":"adf","location":"agd","image_path":""},{"first_name":"test","location":"test","image_path":""},{"first_name":"chris","location":"london","image_path":""}]
Here is my code for the ajax call so far.
function get_fans(){
$.ajax('http://localhost/facebook_app/selectFans/', {
type : 'get',
dataType: 'json',
success : function (data) {
$.each(data, function(index) {
$('section#fans').append('<div class="fan">' + data[index].first_name + ', ' + data[index].location +'</div>');
});
},
error: function () {
$('section#fans').text('Could not load fans.');
}
});
}
This should work :