views:

23

answers:

1

I'm having a very hard time wrapping my head around this problem (it might be the heat from the summer finally arriving).

Problem:
I want the user to press a button client side which performs javascript data preparing and at last send a JSON structure to (currently a asmx webservice on) the server. The JSON structure is several levels deep.

Server side I create a PDF file which I want to send back to the user.

Goal:
The user feeling is that she presses a button and expects a PDF to return to her - either in a new window or as a download (preferrable).

Tools:
The system consists of (client side) HTML, JavaScript and ExtJS and (server side) ASP.NET.

Normally I would use an ashx handler to return a file to the client, but can I send a JSON structure to the handler and still be able to parse it correctly server side?

I am searching for the pattern to use.

+1  A: 

On the client side: submit the JSON string as part of the form data.

On the server side: parse the JSON string (the answers to this question list a number of JSON parsers usable in asp.net) and then generate the PDF. The header

Content-disposition: attachment; filename=something.pdf;

will make the PDF appear as a download for the user.

psmears
Currently I am using AJAX to send the request, is it possible to serve a file from the response from an AJAX request? I can see that my question is a bit to general here :)
Chau
@Chau: I don't think so. I think what you'd normally do here is have an invisible `<iframe>`, and build a form in it using javascript, then submit that form. This doesn't end up being much more complicated than using AJAX really... (Using an `<iframe>` avoids either having to change the URL of the current page, or opening an annoying popup window and/or creating a blank tab, in order to give the user the file download...).
psmears