0

I have a php script that generate a pdf file. So I have an html page with jquery javascript that do an ajax call at this php script and retrieve the pdf file content. I would that this file will be saved in a location choosed by a save file dialog.

How can I do it?

Thank you so much.

michele
  • 26,348
  • 30
  • 111
  • 168

1 Answers1

1

You don't need Ajax - just do a

location.href = "fileURL.php";

(or alternatively, have the user click on a link) and if the headers are set correctly, a download dialog will present itself.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • 1
    Chrome usually opens its built in pdf viewer, but there's the `Content-disposition: attachment` header. – pimvdb Aug 09 '11 at 21:03
  • i think it is not useful because the pdf file is generated passing some $POST variable to the php script – michele Aug 09 '11 at 21:26
  • @michele then create a form with the POST method, and submit it, which will then trigger the download. You can't use Ajax for this, it's impossible to start a file download that way – Pekka Aug 09 '11 at 21:37
  • I can't create a form...how can I do? At the moment I have returned via $ajax the pdf content and I would visualize it or save somewhere. – michele Aug 11 '11 at 10:07