I think the error is causing because of calling the upload event even before we start initiating the XHR request.
$.ajax({
url:"server.php",
beforeSend:function(xhr){
xhr.upload.addEventListener("progress", function(event){
});
},
...
As in the code we are calling xhr.upload.addEventListener("progress"
in beforeSend
. Since we didn't start the request yet, (we are in beforeSend
) we can't have any xhr.upload
object. We can solve this by moving code to xhr
instead of beforeSend
.
Note: you need jQuery version > 1.5.1
$.ajax({
url:"server.php",
xhr: function()
{
var xhr = new window.XMLHttpRequest();
//Upload progress
xhr.upload.addEventListener("progress", function(evt){
...
}, false);
return xhr;
},
Here's the documentation: http://api.jquery.com/jquery.ajax/#jQuery-ajax-url-settings