Created
February 1, 2017 16:41
-
-
Save DmitrySikorsky/c810cad8ae72e5d4647646f51298defe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function uploadFiles(inputId) { | |
var input = document.getElementById(inputId); | |
var files = input.files; | |
var formData = new FormData(); | |
for (var i = 0; i != files.length; i++) { | |
formData.append("files", files[i]); | |
} | |
startUpdatingProgressIndicator(); | |
$.ajax( | |
{ | |
url: "/uploader", | |
data: formData, | |
processData: false, | |
contentType: false, | |
type: "POST", | |
success: function (data) { | |
stopUpdatingProgressIndicator(); | |
alert("Files Uploaded!"); | |
} | |
} | |
); | |
} | |
var intervalId; | |
function startUpdatingProgressIndicator() { | |
$("#progress").show(); | |
intervalId = setInterval( | |
function () { | |
// We use the POST requests here to avoid caching problems (we could use the GET requests and disable the cache instead) | |
$.post( | |
"/uploader/progress", | |
function (progress) { | |
$("#bar").css({ width: progress + "%" }); | |
$("#label").html(progress + "%"); | |
} | |
); | |
}, | |
10 | |
); | |
} | |
function stopUpdatingProgressIndicator() { | |
clearInterval(intervalId); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment