$("input[type='file']#uploadRes").click(function(){ $("#progress").show(); $('#progress .bar').css( 'width', 0 + '%' ); $("#numbar").text(0+"%"); $("input[type='file']#uploadRes").fileupload({ url:"/mng/resource/upload", dataType : 'json', cache:false, replaceFileInput : false, beforeSend:function(){ layer.close(this.layerIndex); }, done:function(e,data){ fileUrl = data.result.fileUrl; fileSize = data.result.fileSize; }, progressall: function (e, data) { var progress = parseInt(data.loaded / data.total * 100, 10); $(".barbox").show(); $('#progress .bar').css( 'width', progress + '%' ); $("#numbar").text(progress+"%"); } }).bind('fileuploadadd', function (e, data) { /* $('#uploadBtn').click(function () { jqXHR = data.submit(); }) */ $('#stopButton').click(function () { data.abort(); }) }).bind('fileuploadfail', function (e, data) { if (data.errorThrown=='abort') { /* alertTips('上傳取消!'); */ }else{ alertTips('上傳失敗!'); } }) });
data.abort()用於取消文件的上傳,該插件不管是請求超時仍是手動取消上傳(jqXHR.abort())都會響應fileuploadfail,可是能夠經過data.errorThrown的值加以區分,見代碼段最後幾行。詳細見博客https://blog.csdn.net/WRian_Ban/article/details/70230732javascript