如何解决多文件上传的Ajax表单验证问题?

时间:2015-10-14 19:04:29

标签: javascript ajax

我现在已经坚持了两个星期..我所有的谷歌搜索链接都是紫色的,我还没有找到解决方案:s

我有一个表格,上传多个文件和2个电子邮件地址。所有的错误验证都有效,但是当我上传文件时,我不能再发送我的表格了。

JAVASCRIPT

<script> 
$(document).ready(function(){
    $( "#uform" ).submit(function( event ) {
        var files = document.getElementsByName("files[]");
        fEmail=$("#fEmail").val();
        yEmail=$("#yEmail").val();

        $.ajax({

            type: "POST",
            url: "upload.php",
            data: "files[]="+files+"&yEmail="+yEmail+"&fEmail="+fEmail,
            success: function(html){ 

                for (var x = 0; x < files.length; x++) {       
                    if(files[x].value == '' || files[x].value == '0'){
                        $("#uploaderror").html("No file selected!");
                    }
                 }

                if (html.trim()=='fEmailError') {
                    $("#uploaderror").html("Please enter a valid Email address!");
                }

                if (html.trim()=='yEmailError')  {
                    $("#uploaderror").html("Please enter a valid Email address!");
                }

                if (html.trim()=='uploadIsSuccess')    {
                    $("#uploadsuccess").html("Success!");
                }

            }

        });
        return false;
    });
});
</script>

1 个答案:

答案 0 :(得分:0)

尝试使用成功/错误/完整回调选项&amp;从那里拿走:

success: function(data) {
    alert(data);
},
error: function (xhr, ajaxOptions, thrownError) {
    alert(xhr.status);
    alert(thrownError);
}