Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have implemented javascript fetch to call webapi in MVC view cshtml page. It is working in Chrome/Edge, but not working in IE. How to make fetch() work in IE.

Below code used in my application for calling MVC action method using fetch()
<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);   });

    });


What I have tried:

I tried adding polyfill as given in code but didn't work.
Posted
Updated 22-Jan-19 1:31am

1 solution

Did you include a polyfill for Promise as well?
You will also need a Promise polyfill for older browsers[^]. We recommend taylorhakes/promise-polyfill[^] for its small size and Promises/A+ compatibility.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900