0

I have a situation here: A HTML form page, on submit returns Excel/PDF/Word document based on POST values, if NOT returns an Error HTML.

With respect to friendly UI, wants to download if everything is fine OR show an error dialog WITHOUT NAVIGATING TO error page. Download works fine. But in case of HTML it navigates based on the response.

Other details:

  1. Backend set content-type to "application/pdf" or whatever
  2. Using jQuery/UI dialog in the front end.
  3. Using jQuery form submit: $("#form").submit();

Any help?

Sha Le
  • 1,261
  • 2
  • 11
  • 10

1 Answers1

0

The way I handle this is:

  • Have the form submit to a hidden iframe.
  • The form includes a hidden field with the name of a cookie the response should set (on success or failure).
  • I show a nice message like "Generating your report" or whatever and poll for the cookie.
  • If the generation is successful, I'll see the cookie with the value "OK" (or similar); this tells me to take down my "generating" message and stop polling.
  • If the generation fails, I'll see the cookie with the value "Error" (or similar); this tells me to read the full error message from the contents of the iframe and show the error to the user.
  • I use a timeout (but a long one, five minutes or something) and also let the user cancel the polling.
  • When returning the PDF, I use a Content-Disposition header to tell suggest to the browser that it should offer to save the result (value attachment) or show it inline (value inline).
Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875