This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Javascript POST DATA HALP!

jdmckinstry wrote on 2011-09-30:
I have my controller setup, works great
I can console the data recieved, looks like pdf data
Tha problem I'm having is simple, I post the data to my controller so I can get a feedback and decide what I want the page to do after, however, i can't find any example of how to take the returned data and show it to user as pdf!!!
I get the raw data back, I've tried adding it to new window, opening new page, and even just changing the whole setup all together and i'm so far beyond confused
my post from js is a (with data added for specific html manipulation)
what do i do with the echoed pdf data?
support wrote on 2011-10-02:
An option is to send pdf data to iframe
<form action="your_pdf_handler" method="post" target="pdf-iframe" id="pdf-form">
   <!-- your post data here --> 
   <input type="hidden" name="foo" value="bar" />
<iframe name="pdf-iframe" src=""></iframe>

and then submit the form using jQuery

Alternatively, instead of echoing pdf data, you could save the generated pdf on your server and return its url in a json response:
  "pdf_url": "/pdfs/my_document.pdf"

and then use like this:
$.post("your_pdf_handler", {your: data}, function(data){