Search code examples
jqueryruby-on-rails-4axlsx

Rails axlsx and ajax


I am trying to generate an excel file to open once the browser has downloaded it. I am using axlsx and I can generate the file fine.

However what I want to do from there is set it up so when I click my link that fires my controller to download my excel file have it show a spinner icon and when the download is complete and excel opening have the spinner icon go away.

I know how to do the javascript to show and hide, I know how to generate the excel file on the rails side. I'm having trouble the two to work together.

Doing a format.js and trying to do ajax that way (using render file) doesnt seem to fire the file javascript in that file, but the Excel opens fine. (I would like to use that file to do the hide of the icon)

The closest thing I have figured out is doing a .on('ajax:complete, function(){ window.open(path to my excel file) code to hide my icon})

And that will open a new tab and then open the downloaded excel file and close the tab.

I'd like to do that without opening a new tab (and preferably without an iframe)

Is this not possible?


Solution

  • In my ajax:complete function I just needed to do something like this

    Download File Using jQuery