Skip to content Skip to sidebar Skip to footer

Trigger Javascript After Fileresult Return In Asp Mvc

I have a Javascript call: window.location.replace(instanceExtension(baseURL + '/AccountsReceivable/PrintStatementOfAccount?clientId=' + clientId, -1)); And the PrintStatementOfAcc

Solution 1:

You can pass token to the method and check for that token in the javascript.

var token = newDate().getTime();
$('#download_token_valueid').val(token); 
$.download(path + "Print.ashx", 'Id=' + id + "&token=" + token);    

fileDownloadCheckTimer = window.setInterval(function () {
        var cookieValue = $.cookie('fileDownloadToken');
        if (cookieValue == token)
            finishDownload();
    }, 1000);

functionfinishDownload() {
    window.clearInterval(fileDownloadCheckTimer);
    $.cookie('fileDownloadToken', null); //clears the cookie value
    $.unblockUI();
}   

Solution 2:

You cannot know from JavaScript whether the file is returned to the browser.

As a workaround instead of returning the file directly you split the process:

  1. File is ready for download: reload the same page with a parameter that somehow identifies the file.
  2. On reloading you read that parameter and save it in a javascript value. Here you can hide the wait mask.
  3. In the page you check if the javascript file identifier is not null, and if not you make a GET request to the server for the file with javascript window.location='url_to_get_file'.

Post a Comment for "Trigger Javascript After Fileresult Return In Asp Mvc"