views:

77

answers:

2

Hi All,

I'm using jquery's $.post and was wondering if I can use this to get a FileResult back? Not having any success yet? The content is coming back in the callback but not as a file download?

Thanks, rodchar

+1  A: 

I don't think this is possible using pure Ajax. You would have to redirect the browser to the file resource somehow. (See my last bullet point for a possible exception from this rule.)

What you could do:

  • Get a file URL back and redirect to it in your success callback: location.href='...'

  • Get a file URL back and set it as the src of a newly created iframe (would prevent current page from closing / freezing) $("#iframe").attr("src", "....");

  • Maybe - I haven't used it myself yet but it looks like it can do this - receive the data and make it a local file download using Doug Neiner's Downloadify

Pekka
+2  A: 

This is not possible.

Instead, you can submit a regular <form> using Javascript that responds with Content-Disposition: attachment.

SLaks
thanks - just what I was looking for
Plumo