Jquery progrees在上传File.Uploading时,百分比栏变得非常快,在10秒内完成,但进度perc在1秒内达到100%。 请帮助我。
$("#regfrm").submit(function(e){
var formObj = $(this);
var formURL = formObj.attr("action");
var formData = new FormData(this);
console.log(formData);
$.ajax({
url: formURL,
type: 'POST',
data: formData,
mimeType:"multipart/form-data",
contentType: false,
processData:false,
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = parseInt(percentComplete * 100);
alert(percentComplete);
$('.myprogress').text(percentComplete + '%');
$('.myprogress').css('width', percentComplete + '%');
}
}, false);
return xhr;
},
success: function(data, textStatus, jqXHR)
{
alert(data)
},
error: function(jqXHR, textStatus, errorThrown)
{
alert('something wrong')
}
});
e.preventDefault();
});