简体   繁体   English

文件上传-在IE8 / IE9上处理

[英]File Upload - Handle on IE8/IE9

I am using the JQuery validation plugin. 我正在使用JQuery验证插件。 As I have found out, I can't use FileData on IE8/IE9. 如我所知,我无法在IE8 / IE9上使用FileData。 The problem is, due to some reasons beyond my control, I also can't use something like IFrame of Flash to handle my files. 问题是,由于某些无法控制的原因,我也无法使用Flash IFrame之类的文件来处理文件。

At the moment, my submitHandler is like the following 此刻,我的submitHandler如下所示

submitHandler: function (form) {
    if( window.FormData === undefined ) {
        alert("UNDEFINED");
    } else {
        formData   = new FormData(),
            params     = $(form).serializeArray(),
            fileOne    = $(form).find('[name="fileOne"]')[0].files,
            fileTwo    = $(form).find('[name="fileTwo"]')[0].files;

        if(fileOne.length != 0) {
            $.each(fileOne, function(i, file) {
                formData.append('fileOne-' + i, file);
            });
        }

        if(fileTwo.length != 0) {
            $.each(fileTwo, function(i, file) {
                formData.append('fileTwo-' + i, file);
            });
        }

        $.each(params, function(i, val) {
            formData.append(val.name, val.value);
        });

        $.ajax({
            type: "POST",
            url: "php/process.php",
            dataType: "json",
            data: formData,
            mimeType: "multipart/form-data",
            contentType: false,
            processData: false
        }).done(function (response) {

            });
        return false;
    }
},

So, it works as normal, but if it does not support FormData, at the moment I have it alerting Undefined. 因此,它可以正常工作,但是,如果它不支持FormData,此刻我会提醒它未定义。 What I need it to do however is keep the validation on the other form fields because this seems to work on IE8, but to ignore anything to do with the uploaded files. 但是,我需要做的是将验证保留在其他表单字段上,因为这似乎可以在IE8上运行,但是可以忽略与上传文件有关的任何事情。 So how would I get it calling my php script for IE8/IE9? 那么,如何为IE8 / IE9调用我的PHP脚本呢?

Any advice appreciated. 任何建议表示赞赏。

Thanks 谢谢

Exclude file validation if FormData object doesn't exist 如果FormData对象不存在,则排除文件验证

if (typeof formData == "undefined") {
   //don't do file validation
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM