Problem in Print PDF by AJAX request

Hi,

I am trying to send the pdf file for the user to download. I am using
send_data method to send the pdf file.

When the user clicks on the “Print PDF” link, the controller method is
called the and the pdf file is saved.

I tried with HTML request(link_to “Print PDF”) and it is working fine.
But when tried with AJAX request,(i.e link_to_remote “Print PDF”), the
pdf is not saved but there is no error logged in the log file.

But I have to pass the ajax request. Why is it not working with
link_to_remote??
And how can I make it working???

Thanks in advance…

IIRC, an Ajax request will actually download the pdf’s contents for the
page’s javascript to handle. You probably want to just do a normal
link_to, not a link_to_remote.

Thanks for your reply. But I gave link_to and link_to_remote as just
examples. Actually I am developing my application using ExtJs. So I can
have only AJAX requests.

So, Is there a way to make it work for AJAX request?

Or is there a way to post HTML request from ExtJs UI?(If you have worked
on ExtJs).

I’m sorry, but I’ve never used ExtJs.

Thanks Mike. I have done it. As it is an AJAX request, the PDF was not
opening.

So I made the button to call the javascript on click, and opened a new
window and passed the URL like this.

window.open(‘my_controller/export_as_pdf’, ‘my_window’)

and it worked.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs