Я тоже сталкивался с этой проблемой, она может пригодиться кому-то нуждающемуся. FormData поддерживается только начиная с IE10 и далее ссылка .Error, потому что вы не можете связывать поля ввода в старых браузерах, как в современных, использующих FormData.Вы не можете загружать файлы через AJAX в IE. Это два альтернативных способа сделать
Используйте какой-нибудь плагин, например плагин Uploadify jQuery, для загрузки файлов через
ajax.Вы также можете использовать jQuery Form Plugin для
multi и uploadify
Другим способом является использование iframe.
Вот код
<code> if(!isAjaxUploadSupported()){ //IE fallfack
var iframe = document.createElement("<iframe name='upload_iframe_myFile' id='upload_iframe_myFile'>");
iframe.setAttribute("width", "0");
iframe.setAttribute("height", "0");
iframe.setAttribute("border", "0");
iframe.setAttribute("src","javascript:false;");
iframe.style.display = "none";
var form = document.createElement("form");
form.setAttribute("target", "upload_iframe_myFile");
form.setAttribute("action", "fileupload.aspx"); //change page to post
form.setAttribute("method", "post");
form.setAttribute("enctype", "multipart/form-data");
form.setAttribute("encoding", "multipart/form-data");
form.style.display = "block";
var files = document.getElementById("myFile");//Upload Id
form.appendChild(files);
$conv("#container_myFile").html("Uploading...");
document.body.appendChild(form);
document.body.appendChild(iframe);
iframeIdmyFile = document.getElementById("upload_iframe_myFile");
// Add event...
var eventHandlermyFile = function () {
if (iframeIdmyFile.detachEvent)
iframeIdmyFile.detachEvent("onload", eventHandlermyFile);
else
iframeIdmyFile.removeEventListener("load", eventHandlermyFile, false);
response = getIframeContentJSON(iframeIdmyFile);
}
if (iframeIdmyFile.addEventListener)
iframeIdmyFile.addEventListener("load", eventHandlermyFile, true);
if (iframeIdmyFile.attachEvent)
iframeIdmyFile.attachEvent("onload", eventHandlermyFile);
form.submit();
return;
}
////var data = new FormData();
//// code go here(for modern browsers)
function isAjaxUploadSupported(){
var input = document.createElement("input");
input.type = "file";
return (
"multiple" in input &&
typeof File != "undefined" &&
typeof FormData != "undefined" &&
typeof (new XMLHttpRequest()).upload != "undefined" );
}
function getIframeContentJSON(iframe){
//IE may throw an "access is denied" error when attempting to access contentDocument on the iframe in some cases
try {
// iframe.contentWindow.document - for IE<7
var doc = iframe.contentDocument ? iframe.contentDocument: iframe.contentWindow.document,
response;
var innerHTML = doc.body.innerHTML;
//plain text response may be wrapped in <pre> tag
if (innerHTML.slice(0, 5).toLowerCase() == "<pre>" && innerHTML.slice(-6).toLowerCase() == "
") {innerHTML = doc.body.firstChild.firstChild.nodeValue;} response = eval (" ("+ innerHTML +") ");}catch (err) {response = {success: false};} обратный ответ;}