Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery文件上传进度条_Javascript_Php_Jquery_Ajax_Zend Framework2 - Fatal编程技术网

Javascript Jquery文件上传进度条

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

使用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
    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请求:

  • 仅发送文件名和大小并验证它

  • 如果有效,请上载该文件。(当然,还要再次验证)

  • 只要我的2美分