<script src="//cdn.jsdelivr.net/bluebird/3.5.0/bluebird.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script> $("#btnExcelDownload").click(function(){ window.fetch("/Home/DownloadExcelTemplate", { method: 'GET', headers: new Headers({ 'AntiForgeryToken': 'XSS6GDB' }) }) .then(response => response.blob()) .then(blob => { var linkElement = document.createElement('a'); var url = URL.createObjectURL(blob); linkElement.setAttribute('href', url); linkElement.setAttribute("download", '@request.Name'+"_Catalog.xlsx"); //for Firefox document.body.appendChild(linkElement); linkElement.click(); document.body.removeChild(linkElement); }); });
Promise
GitHub - github/fetch: A window.fetch JavaScript polyfill.[^]: You will also need a Promise polyfill for older browsers[^]. We recommend taylorhakes/promise-polyfill[^] for its small size and Promises/A+ compatibility.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)