user1406271 user1406271 - 3 months ago 15
Ajax Question

Blueimp file upload script redirects after first uploaded file

Blueimp Jquery file upload script. I need to reload page when the ajax finishes uploading files. I found a solution here and added:

complete: function (e, data) {
window.location = "/result.php";
}


Unfortunately, the script redirects when the first file is uploaded and not when all files finish uploading. What I am doung wrong? Below is my script.

<script>
var defaultthumbnail = '<img class="thumb" src="/upload1.png">';
$(function () {
var formData = $('#fileupload').serializeArray();
'use strict';
$('#fileupload').fileupload({
xhrFields: {withCredentials: true},
url:'//static.example.com',

complete: function (e, data) {
window.location = "/result.php";
}

});


$('#fileupload').fileupload('option', {
acceptFileTypes: /(\.|\/)(jpe?g)$/i,
autoUpload:true,
maxNumberOfFiles:100,
maxFileSize:10000000,

disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent)
});
if ($.support.cors) {
$.ajax({
url: $('#fileupload').fileupload('option', 'url'),
type: 'HEAD'
}).fail(function () {
$('<div class="warning"/>')
.text('error')
.appendTo('#fileupload');
});
}
});
</script>

Answer

Try the callback stop it will help you

$('#fileupload').fileupload({
    xhrFields: {withCredentials: true},
    url: '//static.example.com',

    stop: function (e) {
        console.log('Uploads finished');
        window.location = "/result.php";
    }

});
Comments