Streaming PDF via invocation of HTTPHandler using $.get into object element
Posted
by mythicdawn
on Stack Overflow
See other posts from Stack Overflow
or by mythicdawn
Published on 2010-05-17T09:01:23Z
Indexed on
2010/05/18
22:00 UTC
Read the original article
Hit count: 268
What I am trying to do is invoke an HTTPHandler via the $.get method of jQuery which will stream back a PDF and display it in a web page using an object element. My previous method of setting the src attribute of an IFrame to be the result of a handler invocation works, but I would like cross-browser completion notification, so have moved to using $.get(). Sample code:
function buttonClick() {
$.get("/PDFHandler.ashx", {},
function(data, textStatus, XMLHttpRequest) {
var pdfObjectString = "<object data='' type='application/pdf' width='600' height='600'></object>";
var pdfObject = $(pdfObjectString);
pdfObject.attr("data", data);
$("#container").append(pdfObject);
});
As you can see, I am attempting to stick the 'data' variable into an object element. This is not working (no error, PDF just doesn't display), presumably because the data that comes back is binary, yet the attr() method expects a string (I think).
My question is thus: how can I invoke an HTTPHandler via $.get and somehow assign the data from the callback to the data attribute of an object?
© Stack Overflow or respective owner