English 中文(简体)
HTML OnSubmit:下载或HTML
原标题:HTML OnSubmit: Download OR HTML

我在这里有一种情况:一个HTML表单页面,在提交时返回基于POST值的Excel/PDF/Word文档,如果不是,则返回错误HTML。

关于友好的UI,如果一切正常,希望下载,或者显示一个错误对话框,而不导航到错误页面。下载效果良好。但在HTML的情况下,它会根据响应进行导航。

其他详细信息:

  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();

有什么帮助吗?

问题回答

方式我处理这个是:

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




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签