I have a AJAX script calling my php file pulling images from the database. I want to implement a progress bar for the images whilst it loads. I am getting the images fine from the database, 12 at a time to be specific. I would like to know how to add a progress bar for when the images are being loaded. The images are appended to the div via there path location.
JAVASCRIPT
$.ajax({
url: "/gallery/getimages.php",
type: "POST",
dataType: "json",
data: {
imagesArray: imgArr,
action: "load",
category: q,
isLimited: isLimited
},
success: function(JSONrs) {
JSONconsoleDebugObj = JSONrs;
if(JSONrs.length > 0){
console.log("check returned okay");
console.log("okay ... create page in book");
pageDeets = createPage();
for (var i = 0; i< JSONrs.length; i++){
console.log("okay ... load image" + JSONrs[i]["image_thumb"] );
updateGallery(JSONrs[i],pageDeets[0],tmpNum);
}
createClear(pageDeets[0]);
console.log(tmpNum);
runJumperAnimation(tmpNum);
} else {
runJumperAnimation(pageNum);
}
console.log("jump to " + tmpNum);
},
error: function(jqXHR, textStatus, errorThrown){
console.log(jqXHR.responseText);
console.log(textStatus, errorThrown);
}
});
I'm assuming I can run something between the for loop where it updates the gallery. I just don't know how to implement a progress bar. Effectively I'll need to know the request the server is making i.e the file size and the amount loaded so far. That's where I assume I'll need to use some sort of XMLHttpRequest()
but everywhere on the net talks about base64 encoding the image to do this. This is not an option because the whole script works on the premise of knowing the source of the image via the inline src attribute of the image.