Created
January 16, 2011 12:01
-
-
Save jgonera/781722 to your computer and use it in GitHub Desktop.
JS for file upload progress with gp.fileupload and Nginx module
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 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