我点击下载按钮调用下载servlet。该调用是使用XMLHttpRequest对象的AJAX调用。
var xhr = new XMLHttpRequest();
xmlhttp.open("POST","servlet",true); //servlet will be the servlet name
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(....);
xhr.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
//some logic
}}
我得到的错误:
尽管Fiddler显示了,但仍未显示“另存为”对话框 回复中的文件。
服务器端:标题('Content-type',// mmime类型); header('Content-Disposition','attachment; filename = test.txt');