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 的后备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!