I use this piece of code to upload files via ajax to my website:
jQ(document).on('submit', '#upload_file', function(e) {
e.preventDefault();
jQ('#mensagem').html('<div class="loader" style="text-align: center;">Enviando arquivo...</div>');
jQ.ajaxFileUpload({
url :'<?php echo base_url('chamados/anexar_arquivo')?>',
secureuri :false,
fileElementId :'userfile',
dataType : 'json',
data : {
'desc' : jQ('#desc').val(),
'chamado' : jQ('#codigochamado').val()
},
success : function (data, status)
{
if(data.status != 'error')
{
jQ('#anexos').html('Carregando anexos...');
refresh_files();
jQ('#desc').val('');
var alert = '<div class="alert alert-success fade in"><button type="button" class="close" data-dismiss="alert">×</button>';
}
else
{
var alert = '<div class="alert alert-danger fade in"><button type="button" class="close" data-dismiss="alert">×</button>';
}
jQ('#mensagem').html(alert+data.msg+'</div>');
}
});
});
And it works great! The user choose the file, click "Upload" and then I load a loading gif until it gets replaced by the success - or error - message.
The problem is that when the file is uploading, it shows up on the browser and you can cancel the call click the "X" button on the browser. When I do that the loading gif do not disappears and it keep showing "uploading file..." even if the process of uploading was aborted.
Is there any way to check if the upload was aborted so I can update the screen with an "upload aborted by the user" message?
I tried the error: function(e){}
on the parameters of the ajax call, but it doesn't seem to pass there when the process gets aborted.