Click here to Skip to main content
14,241,167 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100