I am trying to use goog.net.IFrameIO to upload a file and get a JSON response from server after uploaded file is processed. It works fine on Chrome and Safari, but does not with work with IE9 where it errors out with "Acecss Denied to content document", then prompts up to save/open the json response. Here is the html code and js code that I have -
HTML Code:
<form action="/" enctype="multipart/form-data" method="POST" id="upload-form">
<input type="file" name="selected-file" id="selected-file">
<div role="button" class="test-button>Upload</div>
</form>
JS Code:
test.prototype.uploadFile = function() {
// Send the form submission to the server using IframeIo to make it feel like
// AJAX.
var form = /** @type {HTMLFormElement} */ (goog.dom.getRequiredElement(
'upload-form'));
var io = new goog.net.IframeIo();
goog.events.listen(io, goog.net.EventType.COMPLETE, goog.bind(this.processResponse_, this, io));
io.sendFromForm(form, '/uploadfile');
}
test.prototype.processResponse = function(io) {
if (!io.isSuccess()) {
alert('iframeio error encountered:' + io.getLastError());
return;
}
var response = null;
try {
response = io.getResponseJson();
..
} catch (error) {
....
}
I am trying to use closure solution only and not other libraries. I have also went through the question at Fallback AJAX file upload for Internet Explorer but was not able to comment on accepted answer for it.
[Troubleshooting]: I see that method goog.net.IframeIo.prototype.onIeReadyStateChange_() is called with ready states like - loading, interactive and then complete, but is not able to get the content document from iframe created for IE.
HTTP Request Headers: Accept: text/html, application/xhtml+xml, / Content-Type: multipart/form-data Accept-Encoding: gzip, deflate
HTTP Response Headers: X-Frame-Options: SAMEORIGIN Content-Type: application/json; charset=utf-8
The IframeIO library, for IE(version less than 11) creates an iframe to which the HTTP response is posted after file upload.
But iframe in IE9/10(not sure about 8 or 11) does not accept HTTP response with content-type JSON. The response content-type need to be changed to "text/plain" for IE9/10, to make it work.