Internet Explorer 10中是否提供FormData对象?

Cla*_*tta 13 javascript ajax html5 internet-explorer file-upload

我正在编写一个小的JavaScript应用程序,允许我异步上传图像.

这个脚本在每个浏览器中都很棒,除了猜猜谁,Internet Explorer ......

所以我做的第一件事就是使用Ajax的AjaxForm插件为IE9版本创建一个后备版本,这非常有用!

这是JS脚本.

$("#Uploader").change(function(e){
        var form = $("#UploaderForm");
        form.trigger('submit');
        $(this).attr('disabled','disabled');
        e.preventDefault();
});
$("#UploaderForm").submit(function(e){
        e.preventDefault();
        e.stopPropagation();
        var type="POST";var loading=$("#PhotoIsLoading");
        if(windowApi === true){
            var formData = new FormData($(this)[0]);
            $.ajax({
                url: url,
                type: type,
                xhr: function() {
                    myXhr = $.ajaxSettings.xhr();
                    if(myXhr.upload){ myXhr.upload.addEventListener('progress',progressHandlingFunction, false);}
                    return myXhr;
                },
                beforeSend: function(){loading.removeClass('isHidden_important');},
                success: function(response){
                    jres = JSON.parse(response);
                    alert("Test ok, file uploaded");
                },
                error: function(response){console.warn(response);},
                data: formData, 
                cache: false,
                contentType: false,
                processData: false
            });
            e.preventDefault();
        }else{
            $(this).ajaxSubmit({
                url: url,
                dataType: 'json',
                type: type,
                beforeSubmit: function(){loading.removeClass('isHidden_important');$(this).formSerialize();},
                success:function(response){
                    jres = JSON.parse(response);
                    alert("FallbackTest Complete");
                },
                error: function(response){console.warn(response);},
            });
            e.preventDefault();
            return false;
        }
    });
Run Code Online (Sandbox Code Playgroud)

WindowApi并且每个其他变量都在全局脚本中定义但不用担心,它们可以工作.确切地说,WindowApi是这样的:

var windowApi=true;
if(window.File&&window.FileReader&&window.FileList&&window.Blob){
console.log("window.api ready");windowApi=true;}
else{console.log("window.api not ready");windowApi=false;};
Run Code Online (Sandbox Code Playgroud)

所以,有了这一堆代码,我处理每个浏览器和IE9浏览器......

问题现在是IE10,因为它有所有的window.*方法,它可以使用该FormData对象.但是当我尝试使用IE10和FormData上传内容时,我收到了formData对象的"Access Is Denied"错误.

此过程涉及的HTML是:

<form name="UploaderForm" id="UploaderForm" method="post" enctype="multipart/form-data">
    <input type="file" name="Uploader" id="Uploader" accept="image/*" tabindex="1" />
</form>
Run Code Online (Sandbox Code Playgroud)

所以最后我的问题是:

在尝试访问FormData对象时,如何避免在IE10中出现"拒绝访问"异常?

Ale*_*scu 7

/sf/answers/955993321//sf/answers/303477331/可能会有用.IE对于您可以通过<input type='file'>编程方式执行的操作非常严格.

基于第一个,是否更改了第一行来修复这个问题?

$("#Uploader").on('click', function(e){ /* rest of the function unchanged... */
Run Code Online (Sandbox Code Playgroud)