IE 11中的FormData未定义 [英] FormData in IE 11 not defined

查看:1125
本文介绍了IE 11中的FormData未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下脚本,用于从文件的输入类型获取文件数据:

var uploadfiles = $("#upFile").get(0);
var uploadedfiles = uploadfiles.files;

var fromdata = new FormData();
for (var i = 0; i < uploadedfiles.length; i++) {
    fromdata.append(uploadedfiles[i].name, uploadedfiles[i]);
}

// ajax code omitted that uploads file

这在我测试过的所有浏览器中都很好用,除了IE11.在这种情况下,它不了解什么是FormData()?我现在已经在线阅读了很多不同的解决方法,但是它们都不起作用,无论我如何尝试都无法从输入中获取文件的详细信息.有没有其他人可以帮助您的?即使我尝试使用jQuery来获取对象,由于某种原因,文件"也是未定义的.

在线阅读更多内容,这似乎是因为IE在提交表单之前不提供对输入的访问权限,但是我使用Ajax上传文件,所以我无法真正提交它./p>

我还要提到在文件输入的change事件上调用此代码,不确定是否有任何相关性,但最好提一下

解决方案

在IE开发人员工具中检查了docmode后,发现它由于某种原因被还原为9,在我的母版上具有与X-UA-Compatible兼容的较旧的元标记.我更改为的页面:

<meta http-equiv="X-UA-Compatible" content="IE=edge">

FormData完全没有问题.

I have the following script to get the file data from a input type of file:

var uploadfiles = $("#upFile").get(0);
var uploadedfiles = uploadfiles.files;

var fromdata = new FormData();
for (var i = 0; i < uploadedfiles.length; i++) {
    fromdata.append(uploadedfiles[i].name, uploadedfiles[i]);
}

// ajax code omitted that uploads file

This works great in all browsers I have tested with, except IE 11. In this it doesn't understand what FormData() is?? I have read quite a few different workarounds online now but NONE of them work, whatever I try nothing is able to get the details of the file from the input. Has anyone else had this that can help? Even if I try using jQuery to get the object then the 'files' is undefined for some reason.

EDIT: Reading more online, it seems it could be because IE doesn't give access to the input until the form has been submitted, however I am using ajax to upload the file so I can't really submit it.

EDIT2: I should also mention that this code is called on the change event of the file input, not sure if it has any relevance but best to mention it

解决方案

After checking docmode in IE developer tools it turned out it was reverted to 9 for some reason, had an older meta tag for X-UA-Compatible on my master page which I changed to:

<meta http-equiv="X-UA-Compatible" content="IE=edge">

And FormData had no problems at all.

这篇关于IE 11中的FormData未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆