Reputation: 2315
I'm working on JS Ever ajax multiple image uploader. It works really great but one thing. I need the working page reload after all file finish upload. Yes, there's a function to do something after a file uploaded like : success, complete or done. But these callback is per file. It's mean if I add a reload function to it. The page will be reloaded right after the first file is finished upload.
I've tried.
complete:function(file,xhr){alert("ok")}
It works! But it's 3 ok popups since I uploaded 3 files. I need only one "OK" alert after the 3rd file is upload. Please suggest.
$('#uploader').JSAjaxFileUploader({
uploadUrl: 'upload.php',
complete: function (file, xhr) {
$(alert("ok"));
}
});
Upvotes: 0
Views: 2495
Reputation: 492
Can you just add a count?
var count = 0;
var length;
$('#uploader').JSAjaxFileUploader({
uploadUrl: 'upload.php',
complete: function (file, xhr) {
if ( count === 0 ) {
length = $('.JSpreveiw li').length;
}
if ( count === length - 1 ) {
alert('thanks for uploading!');
window.location.reload();
}
count += 1;
}
});
Upvotes: 1
Reputation: 2796
Use a hidden field on the page like <input type="hidden" id="hidUploadCount" value="0" />
Now use function beforesend to track current uploads. And use complete function to reload page if the count is upload in progress is 0 i.e.
$('#uploader').JSAjaxFileUploader({
uploadUrl: 'upload.php',
beforesend:function(){
document.getElementById('hidUploadCount').value+=document.getElementById('hidUploadCount').value;
},
complete: function (file, xhr) {
document.getElementById('hidUploadCount').value-=document.getElementById('hidUploadCount').value;
if(document.getElementById('hidUploadCount').value)==0)
{
alert("ok");//here u can reload the page
}
}
});
Upvotes: 0
Reputation: 1971
If there is a possibility to get the amount of files uploaded, you can make a function in your "complete" callback which increments a number. When that number equals your amount of files, show the alert and refresh the page.
Upvotes: 0