Javascript Jquery文件上传进度条
使用jQueryAjax通过进度条上传视频和图像文件。Im使用服务器端表单验证并检查重复条目。我的问题是在进度条完成后显示验证错误消息。我想要这样的东西Javascript Jquery文件上传进度条,javascript,php,jquery,ajax,zend-framework2,Javascript,Php,Jquery,Ajax,Zend Framework2,使用jQueryAjax通过进度条上传视频和图像文件。Im使用服务器端表单验证并检查重复条目。我的问题是在进度条完成后显示验证错误消息。我想要这样的东西 if form validation is correct then show progress bar else if form validation is not correct then only show error message of form validation else if duplicate entry
if form validation is correct
then show progress bar
else if form validation is not correct
then only show error message of form validation
else if duplicate entry
then only show error message of duplicate entry
这是我的js代码:
$.ajax({
url: ajaxUrl,
type: 'POST',
dataType: 'json',
processData: false,
contentType: false,
async: true,
data: formData,
xhr: function () {
//upload Progress
var xhr = $.ajaxSettings.xhr();
if (xhr.upload) {
xhr.upload.addEventListener('progress', function (event) {
var percent = 0;
var position = event.loaded || event.position;
var total = event.total;
if (event.lengthComputable) {
percent = Math.ceil(position / total * 100);
}
var temp = event.loaded/event.total*100;
//update progressbar
$('div#upload-progress').text(percent + "%");
$('div#upload-progress').css("width", + temp + "%");
}, true);
}
return xhr;
},
complete: function(xhr) {
if(xhr.responseText) {
//console.log(xhr);
}
},
success: function(data, status){
if (data.hasOwnProperty('form-error')) {
$.each(data['form-error'], function (key, value) {
$("span#span_" + key).text(value);
})
} else {
// Form validation is correct
}
},
error : function(xhr, textStatus, errorThrown) {
var data = xhr.responseText;
myWindow = window.open("data:text/html," + encodeURIComponent(data), "parent", "width=1000, height=600");
myWindow.focus();
}
});
有人能给我一些建议吗?我用进度条上传了一个AJAX文件,你可能想看看?我想是吧?
如果您使用服务器验证文件,这意味着必须先上载文件,然后才能进行验证,因此您首先看到进度条。如果只想检查重复项(基于文件名、大小等),则需要2个ajax请求: