Replacing FormData
Recently there was the requirement to upload file using jquery but for some reasons i found out that the uploading thing is working in properly in Firefox, chrome and safari but not functioning in IE(Internet Explorer).After long search, i had to manage the upload with an iframes for IE,below is the function that did magic :) enjoy
function fileUpload(form, action_url, div_id) {
// Create the iframe...
var iframe = document.createElement("iframe");
iframe.setAttribute("id", "upload_iframe");
iframe.setAttribute("name", "upload_iframe");
iframe.setAttribute("style", "border: none;display: none;");
// Add to document...
form.append(iframe);
window.frames['upload_iframe'].name = "upload_iframe";
iframeId = document.getElementById("upload_iframe");
// Add event...
var eventHandler = function () {
if (iframeId.detachEvent) iframeId.detachEvent("onload", eventHandler);
else iframeId.removeEventListener("load", eventHandler, false);
// Message from server...
if (iframeId.contentDocument) {
content = iframeId.contentDocument.body.innerHTML;
} else if (iframeId.contentWindow) {
content = iframeId.contentWindow.document.body.innerHTML;
} else if (iframeId.document) {
content = iframeId.document.body.innerHTML;
}
//getting the response from server
content = content.replace("
","").replace("","");
alert(content);
}
if (iframeId.addEventListener) iframeId.addEventListener("load",eventHandler,true);
if (iframeId.attachEvent) iframeId.attachEvent("onload", eventHandler);
// Set properties of form...
form.attr("target", "upload_iframe");
form.attr("action", action_url);
form.attr("method", "post");
form.attr("enctype", "multipart/form-data");
form.attr("encoding", "multipart/form-data");
form.submit();// Submit the form...
}
and that's is all, i hope this could help someone.find the full source here :
https://github.com/oniadebowale/FormDataWorkAround