0

I have a Javascript call:

window.location.replace(instanceExtension(baseURL + "/AccountsReceivable/PrintStatementOfAccount?clientId=" + clientId, -1));

And the PrintStatementOfAccount() method takes a few seconds so I've added a mask to the page indicating that the PrintStatement is loading.

The ASP method is defined as:

public FileResult PrintStatementOfAccount(long clientId) { ... }

All works great, but I would like to disable the wait mask once the file returns. Any ideas on how I can achieve this?

2 Answers 2

1

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

var token = new Date().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);

function finishDownload() {
    window.clearInterval(fileDownloadCheckTimer);
    $.cookie('fileDownloadToken', null); //clears the cookie value
    $.unblockUI();
}   
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the suggestion dotnet, I would rather avoid polling for the status though, wish there was another way...
1

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'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.