Reputation: 2577
I have this ajax file upload form with an abort(); function. which is triggered by clicking cancel anchor:
$('#cancel').click(function(){
ajaxFileUpload.abort();
$('#message').html('cancelled');
});
and this anchor is hidden when the success function returns 'successfullyUploaded':
if(response == 'successfullyUploaded') {$('#cancel').hide(); });
at which point the files are uploaded and it's too late to cancel the upload. For the most part it works pretty well. However if someone clicks 'cancel' in the instant between the files uploading on the php page which handles the upload, and the page containing the form receiving the success data it will say 'cancelled' but in fact the upload has been completed. So I was wondering if there was some way to detect when the file upload is at, say, 95% complete, and at that point, hide the 'cancel' anchor. Is this at all possible? Thanks
Upvotes: 2
Views: 879
Reputation: 15847
Upon abort you may send a second AJAX request to the server telling that the upload have been canceled and the uploaded file (if present) must be deleted.
As you receive success response from the second request you can set #message to canceled
Upvotes: 1