开发者

HTML OnSubmit: Download OR HTML

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 everythi开发者_运维技巧ng 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?


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).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜