To answer my own question, creating an iframe containing a form and
then submitting the form works as I want it to. No AJAX needed:

var records = $("<input>").attr(
{
        //"type": "hidden", // doesn't work in IE
        "name": "records",
        "value": checkedItems
});
var form = $("<form>").attr(
{
        "method": "post",
        "action": "report.ashx"
}).append(patients)[0];
// create a iframe and hide it
var iframe = $("<iframe>").hide()[0];
// append to body
$("body").append(iframe);
// get document object in iframe (contentWindow is for IE)
var d = iframe.contentDocument || iframe.contentWindow.document;
// open the document
d.open();
// write the form to the page (by appending to a div and getting the
html it contains
d.write($("<div>").append(form).html());
// close the document and submit the form in it
d.close();
d.forms[0].submit();

On 16/11/06, Sam Collett <[EMAIL PROTECTED]> wrote:
> I have a WebHander that returns a binary file (PDF to be precise). How
> can I use AJAX to display that file in the browser? Returned content
> type is "application/pdf" and it is sent with the header
> "Content-disposition:attachment; filename=report.pdf" so it forces a
> download.
>
> var checkedItems = [];
> $("[EMAIL PROTECTED]:checked", mytable).each(
>         function()
>         {
>                 checkedItems.push(this.value);
>         }
> );
> $.ajax(
> {
>                 type: "POST",
>                 url: "report.ashx",
>                 data: "records=" + checkedItems,
>                 success: function(msg)
>                 {
>                         // what goes here?
>                 }
>         }
> );
>
> The only other solution I can think of is to do:
>
> location.href = "report.ashx?records=" + checkedItems
>
> but I would like to avoid that if possible.
>

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to