Skip to content

Instantly share code, notes, and snippets.

@jgonera
Created January 16, 2011 12:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgonera/781722 to your computer and use it in GitHub Desktop.
Save jgonera/781722 to your computer and use it in GitHub Desktop.
JS for file upload progress with gp.fileupload and Nginx module
function pollGp() {
$.ajax({
type: 'GET',
url: '/gp.fileupload.stat/${c.upload_id}',
cache: false,
dataType: 'json',
timeout: 5000,
success: function(response) {
if (response.state == 1) {
$('#progressbar div').css('width', response.percent + '%');
}
}
});
}
function pollNginx() {
$.ajax({
type: 'GET',
url: '/nginx_upload',
data: {'X-Progress-ID': ${c.upload_id}},
cache: false,
dataType: 'json',
timeout: 5000,
success: function(response) {
if (response.state == 'uploading') {
$('#progressbar div').css('width', (response.received / response.size * 100) + '%');
}
},
error: pollGp
});
}
$(document).ready(function() {
$('form').submit(function() {
$('<p>Proszę czekać...</p><div id="progressbar"><div></div></div>').appendTo('form');
$('button').attr('disabled', 'disabled');
window.setInterval(function () {
pollNginx();
}, 5000)
return true;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment