2

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.

Chau
  • 5,540
  • 9
  • 65
  • 95

1 Answers1

1

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.

Community
  • 1
  • 1
psmears
  • 26,070
  • 4
  • 40
  • 48
  • 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 Jul 02 '10 at 12:04
  • 1
    @Chau: I don't think so. I think what you'd normally do here is have an invisible ` – psmears Jul 02 '10 at 13:49