Not sure am I had missused new Image(), I'm experiencing strange order of object of my json object using below code.
$.ajax({
type: 'GET',
url: '/' + getUsername() + '/photos',
success: function(data) {
if (data.length > 0) {
$.each(data, function() {
var caption = this.caption
var albumPhoto = '';
albumPhoto = 'http://example.com/' + this.photo;
var temp_img = new Image(),
albumPhotoWidth, albumPhotoHeight
temp_img.src = albumPhoto;
temp_img.onload = function() {
var photosObj = {
src: albumPhoto,
title: caption,
w: this.naturalWidth,
h: this.naturalHeight
};
pswpAlbum_Items.push(photosObj);
}
});
}
}
});
}
pswpAlbum_Items result is not consistent, the order of my photo is not consistent, I found the bug when I try in private mode where browser never get cached images. Any clue why?