Fallback for FormData in IE 8/9(IE 8/9 中 FormData 的后备)
问题描述
FormData 在 IE 8/9 中不存在,但我需要这些浏览器中的功能.有一个很好的后备方案吗?
FormData does not exist in IE 8/9 but I need that functionality in those browsers. Is there a nice fallback for this?
我会尝试通过 json 数据发送,但我需要将文件传递给服务器.我将此文件附加到现代浏览器中的 formData 并提交一个 XHR 请求.因为 FormData 在 IE 8/9 中不存在,这显然失败了.
I would try to send over json data, but I need to pass over a file to the server. I append this file to the formData in modern browsers and just submit an XHR request. Because FormData does not exist in IE 8/9 this obviously fails.
// I cant seem to get this to work with a file.
$.ajax({
url: '/genericHandlers/UploadDocsFile.ashx',
type: "POST",
data: model.toJSON(),
contentType: 'application/json'
}).done(function (data) {
log('stuff happened!');
});
也许另一种方法是在 js 中创建一个假表单对象,然后将数据附加到该对象?
Maybe an alternative is to create a fake form object in js then append the data to that?
推荐答案
我只知道一种可能的解决方案,但这并不是 IE 真正的 1-1 后备方案.没有可能用于发送文件的通信 API,因为您无法在旧浏览器中绑定输入字段,例如在使用 FormData 的现代浏览器中.但是您可以使用 iframe 发送整个表单.对于这种情况,您可以使用支持 XHR DataForm 和 iframe 的 jquery.form 插件(当浏览器不支持 FormData API 时使用 iframe 发送数据).
I know only one possible solution, but it's not really 1-1 fallback for IEs. There are no possible communication API for sending files, because you cannot bind input fields in old browsers, like in a modern ones using FormData. But you can send whole form using an iframe. For this case you can use jquery.form plugin that support XHR DataForm and iframe (data sends with iframe when browser do not FormData API support).
这篇关于IE 8/9 中 FormData 的后备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:IE 8/9 中 FormData 的后备
基础教程推荐
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
