2
AJAX呼び出しでサーバーからファイルをダウンロードしたいとします。 XMLHttpRequestからのオクテットストリームを処理する方法
var ifrm = document.getElementById("fileframe");
ifrm.src = "DownloadFile?fileid="+fileid;
しかし、私は、より複雑な問題を持っている: それは次のように
iframe
を使用することにより簡単に行うことができます。
アプリケーション/オクテットストリームの代わりに、コンテンツタイプが 'text/html'の応答がバックエンドによって返される場合もあります。
私はXMLHttpRequest
のファイルをダウンロードするための呼び出しを使用する予定です。 を使用してXMLHttpRequest
アプリケーション/オクテットストリームを処理するためのファイル保存ダイアログをポップアップするブラウザを作成するにはどうすればよいですか?
// connect function handles the XMLHttpRequest communication with the backend
var connection = connect('DownloadFile','fileid='+fileid);
connection.onreadystatechange = function(){
if(connection.readyState == 4) {
var contentType = connection.getResponseHeader('Content-Type');
if(contentType == 'application/octet-stream'){
// here I want to make the browser popup a save file dialog
// for the incoming octet stream
// maybe I can direct stream to an iframe, but how??
}else{
alert(connection.responseText);
}
}
if((connection.readyState == 2)||(connection.readyState == 3)){
}
}