Ajax Request PDF to IFRAME

1,440 views
Skip to first unread message

kstubs

unread,
Feb 8, 2010, 5:34:12 PM2/8/10
to Prototype & script.aculo.us
I'm fetching (with Ajax call) a dynamic PDF from the server and would
like the results to load into an Iframe (or other html embeded/
object).

Is this possible?

Karl..

Peter De Berdt

unread,
Feb 8, 2010, 6:06:48 PM2/8/10
to prototype-s...@googlegroups.com
You should be able to set the location or src of the iframe from an Ajax call, which would trigger that iframe to load the PDF.


Best regards


Peter De Berdt


kstubs

unread,
Feb 8, 2010, 6:15:23 PM2/8/10
to Prototype & script.aculo.us
Since the PDF is dynamically generated, the source is the streamed
result of the ajax request. The iframe has no way to submit a POST to
a server,but instead, can I stream to the iframe somehow, the ajax
response?

T.J. Crowder

unread,
Feb 8, 2010, 6:22:42 PM2/8/10
to Prototype & script.aculo.us
Hi,

> Is this possible?

Possible? It's downright easy:

$('idOfIFrame').src = "pathToYourServerScript.xyz";

Very important that your server script set the correct content type,
of course.

I use something similar with a frame (not an iframe), but the concept
should be transferrable.

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com

kstubs

unread,
Feb 8, 2010, 7:03:29 PM2/8/10
to Prototype & script.aculo.us
It must be a post to the server, not a get.

Peter De Berdt

unread,
Feb 9, 2010, 3:29:45 AM2/9/10
to prototype-s...@googlegroups.com
Generate a form with the necessary values in the iFrame and submit the form. That's all I can think off right now.

On 09 Feb 2010, at 01:03, kstubs wrote:

It must be a post to the server, not a get.

On Feb 8, 4:22 pm, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
Hi,

Is this possible?

Possible? It's downright easy:

    $('idOfIFrame').src = "pathToYourServerScript.xyz";

Very important that your server script set the correct content type,
of course.

I use something similar with a frame (not an iframe), but the concept
should be transferrable.


T.J. Crowder

unread,
Feb 9, 2010, 10:05:10 AM2/9/10
to Prototype & script.aculo.us
Hi,

> It must be a post to the server, not a get.

Okay, that's a *few* more lines of code:

var markup, form;

markup =
"<form id='___unique_form_id___' " +
"method='POST' " +
"action='yoururl' " +
"target='theIFrameName' " +
"style='display: none'>" +
"<input type='hidden' name='param1' value='value1'>" +
"<input type='hidden' name='param2' value='value2'>" +
"</form>";
$(document.body).insert({bottom: markup});
form = $('___unique_form_id___');
form.submit();
form.remove();

Quick test on IE7, FF3.6, and Chrome4 all seemed happy. (I wondered if
I might need a defer in there, but apparently not.)

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com

T.J. Crowder

unread,
Feb 9, 2010, 10:06:26 AM2/9/10
to Prototype & script.aculo.us
Blast (I *hate* double posting), forgot to say: By "theIFrameName" in
that code I mean literally the value of a `name` attribute on the
`iframe` tag (*name*, not *id*).

-- T.J. :-)

On Feb 9, 3:05 pm, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> Hi,
>

kstubs

unread,
Feb 12, 2010, 2:59:41 AM2/12/10
to Prototype & script.aculo.us
Well thanks for the help on posting a request to the iframe to handle
the PDF. Here is my bigger problem and the reason for my original
thought: how do you trigger code on completion of the PDF load in the
iframe? Of course the original thought was to make an ajax request and
and write the results to the iframe. You then know when therequest is
complete and I'm sure writing to the iframe is fast enough. Is this
possible? Can I get back a binary result from an Ajax request and can
I binary write to the iframe?
Thanks
Karl..
Reply all
Reply to author
Forward
0 new messages