$this.printAsset = function () {
var selectedIds = selectedAssetIds();
if (selectedIds.length == 0) {
bootAlert('请选择资产');
return false;
}
window.location.href = '/Asset/Print?ids=' + selectedAssetIds();
};
网上扒的一段代码,点击一个按钮后触发这个方法,之后会下载一个 excel 文件。
不太清楚的是:触发方法后,浏览器上面显示的地址没有改变成http://example.com/Asset/Print?ids=**
,而且Chrome的network也没有监听到任何网络请求。一开始以为excel是纯前端生成的,但是直接在浏览器地址栏输入地址http://example.com/Asset/Print?ids=**
,excel依然能够被下载。
很尷尬,很简单的问题,一下没想出来。应该是发送这个请求http://example.com/Asset/Print?ids=**
后,后台经过处理返后回一个文件。也就变相的等于一个下载功能吧。
能不能实现ajax不清楚,不过这个
window.location.href = '/Asset/Print?ids=' + selectedAssetIds()
相当于打开一个文件,而浏览器打开文件时候会进行下载。