gpt4 book ai didi

javascript - 使用适用于 IE 的 Ajax 进行文件发布

转载 作者:行者123 更新时间:2023-11-28 20:05:58 25 4
gpt4 key购买 nike

以下是我的 Ajax 调用,它在所有浏览器中都能正常工作,但到目前为止仅在 IE 中出现问题。请告诉我如何使用 Ajax 发布文件,并且发布最高应支持 IE 6。

var formData = new FormData(document.getElementById('form'));

$.ajax({
type: "POST",
url: "email.php",
data: formData,
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
success: function(html){
if (html.indexOf("filerror") != -1)
{
alert('error');
}
else if(html.indexOf("true") != -1)
{
alert('true');
}
else if (html.indexOf("false") != -1)
{
alert('false');
}
},
beforeSend:function()
{

}
});

最佳答案

IE6 不支持 HTML5 的 FormData 对象,该对象允许使用 AJAX 上传文件。抱歉,您将不得不诉诸更多的石器时代技术来实现这一目标,例如隐藏的 iframe 或 flash 电影。您也可以考虑使用插件,例如 UploadifyjQuery form plugin它将检测客户端浏览器的功能,并根据它们使用最好的技术。这样您就不需要处理和维护一些已死的和埋在地下的浏览器(例如 IE6)的代码。

关于javascript - 使用适用于 IE 的 Ajax 进行文件发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20803176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com