Jquery无须浏览实现直接下载文件
通常GET方式:后面带明文参数,不安全。 window.location.href = 'http://localhost:1188/FileDownload.aspx?token=SCBC#’; 1、通过XMLHttpRequest+ HTML5 Blob对象 jQuery.download_XMLHttpRequest = function (url, fn, data, method) { // 获得url和data var xhr = new XMLHttpRequest(); xhr.open(method, url, true);//get请求,请求地址,是否异步 xhr.responseType = "blob"; // 返回类型blob xhr.onload = function () {// 请求完成处理函数 if (this.status === 200) { var blob = this.response;// 获取返回值 if (navigator.msSaveBlob) // IE10 can't do a[download], only Blobs: { window.navigator.msSaveBlob(blob, fn); return; } if (window.URL) { // simple fast and modern way