Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery to re-enable form after a file result is returned

I have an ASP.NET MVC form that returns a report as a File(...) result. This means that the browser stays on the current page after the file download is triggered. Using jQuery, I would like to disable the submit button and then re-enable it after the file returns. My code already disables the button just fine, however, I'm unable to find an event to hook into that is triggered after the file returns.

Here's what I have so far:

  $(document).ready(function() {
        $("#downloadForm").submit(function() {
            $("#cmdSubmit").attr("disabled", "disabled");
            $("#uiProgress").show();
        });
    });

What can I add to this to trigger when the form submit returns?

like image 214
Daniel Avatar asked Jun 08 '09 21:06

Daniel


1 Answers

You may have to complicate the process: rather than returning the File from the post, have #downloadForm post an AJAX request that returns the URL to the file. When the response is received, you can reenable your button and set document.location to the returned URL.

like image 70
Dan Davies Brackett Avatar answered Nov 15 '22 07:11

Dan Davies Brackett