Serving file from AJAX call

Glenn Cadman wrote:

How do I inside a AJAX form_remote_tag construct, create a button that when clicked will do the following: a) The controller will have the params of the form available to modify the results(ie the search filter value), I can get excel start with a link_to a different controller but the values of the form are not available (or I dont know how to access or include them in a link_to call) b) Popup, render or send_data or any way to send a full page with the correct headers to have a browser start excel.

Change the form to a normal form, with its target parameter optionally set to "_blank", and change the AJAX submit to submit_to_remote.

Glenn Cadman wrote:

Mark Reginald James wrote:

Change the form to a normal form, with its target parameter optionally set to "_blank", and change the AJAX submit to submit_to_remote.

With the submit_to_remote what is the :update target? I just cannot see how the html header will be refreshed?

It's the AJAX search that should be a submit_to_remote. The Excel button should instead be a normal submit button:

<%= form_tag({:action => 'search_excel'}, :target => '_blank') %> <%= text_field_tag 'terms' %> <%= submit_to_remote nil, 'Search', :url => {:action => 'search'}, :update => :results %> <%= submit_tag 'Search and display results in Excel' %> </form>

<div id="results"> ..table of results </div>

Glenn Cadman wrote:

OK I found one issue with the user interface, should the user hit return in the filter wizard (form) he/she will popup a excel sheet and for them this is misterious because they didnt click on the excel button?

How can I disable posting if user hits the enter key?

Yeah, that's a bit of fly in the ointment. Here's one way to switch the enter key from Excel to AJAX search:

<%= form_tag({:action => 'search_excel'}, :target => '_blank') %> <%= text_field_tag 'terms', nil,      :onkeypress => "return event.keyCode != 13 || ($('s').click(),false)" %> <%= submit_to_remote nil, 'Search', :url => {:action => 'search'},                                      :update => :results, :html => {:id => 's'} %> <%= submit_tag 'Search and display results in Excel' %> </form>