If you want to create a seamless AJAX file download experience, consider using a hidden IFRAME element to handle the file download request. This way, your users can continue interacting with the form on the client side while the file is being downloaded.
Additionally, you have the flexibility to call a webservice, aspx page, or HTTP handler within the URL for the file download.
function dowloadFileJS() {
// Create an IFRAME.
var iframe = document.createElement("iframe");
// Point the IFRAME to GenerateFile
iframe.src = "GenerateFile.aspx?yourQueryString=myQueryString";
// Make the IFRAME invisible to the user.
iframe.style.display = "none";
// Add the IFRAME to the page. This triggers the request to GenerateFile immediately.
document.body.appendChild(iframe);
}