Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
function uploadWithProgress(file) { const $bar = $("#upload-bar"); return $.ajax({ url: "/api/upload", method: "POST", data: (() => { const fd = new FormData(); fd.append("file", file); return fd; })(), processData: false, contentType: false, xhr: function() { const xhr = $.ajaxSettings.xhr(); xhr.upload.addEventListener("progress", e => { if (e.lengthComputable) $bar.css("width", (e.loaded/e.total*100) + "%").attr("aria-valuenow", e.loaded/e.total*100); }); return xhr; } }); }
Result
Open