Browser 如何在浏览器中打开自动下载的Word文档?
我使用Aspose生成Word文档。当它从服务器返回时,必须在浏览器中自动打开它 这是我的密码: 执行Ajax调用以获取文档Browser 如何在浏览器中打开自动下载的Word文档?,browser,stream,aspose,Browser,Stream,Aspose,我使用Aspose生成Word文档。当它从服务器返回时,必须在浏览器中自动打开它 这是我的密码: 执行Ajax调用以获取文档 $.ajax({ url: "Export/StreamWord", data: { topicId: CurrentTopic.id }, success: function (result) { //Nothing here. I think that the browser must o
$.ajax({
url: "Export/StreamWord",
data: { topicId: CurrentTopic.id },
success: function (result) {
//Nothing here. I think that the browser must open the file automatically.
}
});
控制器.NETMVC3
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult StreamWord(string topicId)
{
var stream = new MemoryStream();
Document doc = exportRepos.GenerateWord(topicId); //Document is a Aspose object
doc.Save(stream, SaveFormat.Docx);
stream.WriteTo(Response.OutputStream);
return File(stream, "application/doc", "test.doc");
}
但是当我从浏览器运行它时,什么都没有发生。
您可以在图像上看到服务器的响应。文档已打开,但尚未打开
有什么建议吗?不要为此使用AJAX,只需使用简单的页面重定向即可。如果使用页面重定向,它将提示用户下载文件,实际上不会将其从当前页面移开 代码看起来像
document.location.href = "Export/StreamWord?topicId=" + CurrentTopic.Id;
使用AJAX无法实现您的尝试。很好!今天我学到了一些新东西!非常感谢!:)没问题,这就是我们来这里的目的:)