1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
$.ajax({
xhr: function()
{
var xhr = new window.XMLHttpRequest();
//Upload progress
xhr.upload.addEventListener("progress", function(evt){
console.log("upload percentComplete : "+evt.loaded+" / "+evt.total+"\nEvent : "+evt.length+"\nratio : "+Math.round(evt.loaded/evt.total * 100)+" %");
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
//Do something with upload progress
console.log("upload percentComplete : "+evt.loaded+" / "+evt.total+"\nEvent : "+evt.length+"\nratio : "+Math.round(evt.loaded/evt.total * 100)+" %");
}
}, false);
//Download progress
xhr.addEventListener("progress", function(evt){
console.log("percentComplete : "+evt.loaded+" / "+evt.total+"\nEvent : "+evt.length+"\nratio : "+Math.round(evt.loaded/evt.total * 100)+" %");
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
//Do something with download progress
console.log("percentComplete : "+percentComplete);
}
}, false);
return xhr;
},
type: 'POST',
url: url,
data: {},
success: function(data){
//Do something
}
}); |
Partager