$.ajax({ xhr: function() { var xhr = new window.XMLHttpRequest(); //Upload progress xhr.upload.addEventListener("progress", function(evt){ if (evt.lengthComputable) { var percentComplete = evt.loaded / evt.total; //Do something with upload progress console.log(percentComplete); } }, false); //Download progress xhr.addEventListener("progress", function(evt){ if (evt.lengthComputable) { var percentComplete = evt.loaded / evt.total; //Do something with download progress console.log(percentComplete); } }, false); return xhr; }, type: 'POST', url: "/", data: {}, success: function(data){ //Do something success-ish } }); This does not work on jQuery 1.5+ because the xhr is replaced by the jqXHR (i.e. a high level version of the raw XHR.) Now the question is how to get it to work with jqXHR… Anyone know how to do it?
$.ajax()returns a jqXHR object, which implements the Promise interface. I guess that you can monitor progress with '$.ajax(...).progress(callback). Unfortunately, I can't find a full refernce so can't advise of what parameters the callback accepts, though it's probably the same as adone` (success) callback, ie.function(data, textStatus, jqXHR){...}. The jqXHR Object exposes a bunch of properties and methods which can be exploited in the callback.