0

I'm downloading a file via window.location.href = '..path to server get method which returns file'

Here is my code on button click,

$(document)
            .off('click', '#btnExportToExcel')
            .on('click', '#btnExportToExcel',
                function (e) {
                    e.preventDefault();

                    indicatorStart('Loading');
                    window.location.href = '/Index/ExcelReport';
                    indicatorStop();
                    });

Here is my indicatorStart() and indicatorStop(),

function indicatorStart(text) {
    const $loader = $($.parseHTML(`<div id="loader" class="fade show">
                                        <div id="loader-message" role="alert">${text}</div>
                                     </div>`));

    $('.page-content').append($loader);
}

function indicatorStop() {
    $('#loader').remove();
}

loader works when I hook this method inside ajax lifecycle but not under normal get. Only file is getting downloaded correctly. Please assist on where I'm going wrong.

fingers10
  • 6,675
  • 10
  • 49
  • 87
  • Dang, this for sure aren't meant to work in any possible environment. Load your file in a binary form with this JS in order to handle download process. – lucifer63 Jul 30 '19 at 10:28
  • That's what my server does. It returns the file in binary form. I'm using asp.net core backend and my Excel is getting downloaded perfectly – fingers10 Jul 30 '19 at 10:49
  • i can only repeat the first message: `"Load your file in a binary form with JS in order to handle download process"` – lucifer63 Jul 30 '19 at 10:53
  • any samples/examples? am I doing thing wrongly? I new to js. please assist – fingers10 Jul 30 '19 at 11:14
  • 1
    `"Any samples?"` - sure, many samples, like this one - https://stackoverflow.com/questions/17696516. `"am I doing thing wrongly"` - yes, like i already said. This `indicatorStart/Stop` system is not supposed to work, forget about it – lucifer63 Jul 30 '19 at 11:17
  • 1
    Note that you can track downloading progress only if you download file with JS. In any other case the browser tracks downloading process; google `xhr onprogress` – lucifer63 Jul 30 '19 at 11:18

0 Answers0