Reputation: 34160
I'm using $.post for uploading files to server. File upload will take sometime based on the size of the file. So what I want to do is to give user the option to cancel file upload ($.post) before the upload completes:
var file = document.getElementById('file').files[0];
$.post('/upload.aspx',
{file : file},
function(data){
//upload completed
}
);
Any suggestion?
Upvotes: 3
Views: 56
Reputation: 1074385
The underlying XMLHttpRequest
object has an abort
method on most browsers, so:
var file = document.getElementById('file').files[0];
var xhr = $.post('/upload.aspx',
{file : file},
function(data){
//upload completed
}
);
// Later if aborting it
if (xhr.abort) {
xhr.abort();
}
Upvotes: 1