goog.net.IFrameIO を使用してファイルをアップロードし、アップロードされたファイルが処理された後にサーバーから JSON 応答を取得しようとしています。Chrome と Safari では正常に動作しますが、IE9 では動作せず、「コンテンツ ドキュメントへのアクセスが拒否されました」というエラーが発生し、json 応答を保存/開くように求められます。これが私が持っているhtmlコードとjsコードです-
HTML コード:
<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 コード:
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) {
....
}
他のライブラリではなく、クロージャ ソリューションのみを使用しようとしています。また、Internet Explorer のフォールバック AJAX ファイルのアップロードで質問をしましたが、受け入れられた回答についてコメントできませんでした。
[トラブルシューティング]: メソッド goog.net.IframeIo.prototype.onIeReadyStateChange_() が、ロード中、インタラクティブ、完了などの準備完了状態で呼び出されますが、IE 用に作成された iframe からコンテンツ ドキュメントを取得できません。
HTTP リクエスト ヘッダー: Accept: text/html、application/xhtml+xml、/ Content-Type: multipart/form-data Accept-Encoding: gzip、deflate
HTTP 応答ヘッダー: X-Frame-Options: SAMEORIGIN Content-Type: application/json; 文字セット=utf-8