我的代码发布了ajax请求,但它没有显示进度条.请帮助更正代码以显示工作进度条.
$(document).ready(function () { $("#uploadbutton").click(function () { var filename = $("#file_path$i").val(); //get form data; $.ajax({ type: "html",url: "share.PHP",//onwhich post ajax data; enctype: 'multipart/form-data',data: { file: filename },success: function () { alert("Data Uploaded: "); } }); }); });
解决方法
@whitneyit:我们可以使用xhr:ajax函数跟踪文件上传这样的东西
$.ajax({ url: 'handler/FileUploader.ashx?FileName=' + file.name,//server script to process data type: 'POST',xhr: function () { myXhr = $.ajaxSettings.xhr(); if (myXhr.upload) { myXhr.upload.addEventListener('progress',progressHandlingFunction,false); } return myXhr; },success: function (result) { //On success if you want to perform some tasks. },data: file,cache: false,contentType: false,processData: false }); function progressHandlingFunction(e) { if (e.lengthComputable) { var s = parseInt((e.loaded / e.total) * 100); $("#progress" + currFile).text(s + "%"); $("#progbarWidth" + currFile).width(s + "%"); if (s == 100) { triggerNextFileUpload(); } } }