简体   繁体   English

以AJAX格式上传文件和相应的数据

[英]Upload a file and corresponding data in an AJAX form

I need to upload a file with a form in a single-page (AJAX) web application, but the file is useless without the rest of the data on the form in that panel. 我需要在单页(AJAX)Web应用程序中上载带有表单的文件,但是如果没有该面板中表单上的其余数据,该文件将无用。 There are only three INPUT s, but one can be a quite lengthy text area. 只有三个INPUT ,但是一个可以是一个相当长的文本区域。 How can I capture this? 我该如何捕捉呢?

If I upload the file using an isolated AJAX file-upload technique (like the Fine Uploader http://fineuploader.com/ widget), then I have to handle two counter-intuitive elements: 如果我使用隔离的AJAX文件上传技术(例如Fine Uploader http://fineuploader.com/小部件)上传文件,那么我必须处理两个违反直觉的元素:

  • CLIENT: The user transmits the file, the main part of the transaction, before actually approving the transaction. 客户:用户在实际批准交易之前传输文件(交易的主要部分)。 They then wait for this to complete, even if they decline to continue. 然后,即使他们拒绝继续,他们也等待完成。 The UI must disable screen elements to prevent the scenario where a client might submit the associated data before or during the file upload. UI必须禁用屏幕元素,以防止客户端可能在文件上载之前或期间提交关联数据的情况。 It's extra effort to send the file at the wrong point in the process. 在此过程中错误的位置发送文件是额外的努力。

  • SERVER: It requires a ticketed-cache. 服务器:它需要票证缓存。 The back-end must cache the uploaded file and provide a ticket to the client for this file. 后端必须缓存上载的文件,并向客户端提供该文件的票证。 The client must send this ticket with the upcoming request. 客户必须将此票证与即将到来的请求一起发送。 Ideally, the cache also should clean up old tickets under various circumstances, such as if the form is cancelled, another file is uploaded, or the user session times out. 理想情况下,高速缓存还应在各种情况下清理旧票证,例如,取消表单,上载另一个文件或用户会话超时。 More extra work (although this ticketed-cache functionality would be nice to have in my server). 需要更多的额外工作(尽管在我的服务器中可以使用此票务缓存功能会很不错)。

Is it a sensible solution to instead place the whole form in an IFRAME ? 将整个表单放在IFRAME是明智的解决方案吗? Will I have problems manipulating that and making it appear to be a well-integrated part of the single-page application? 我在操纵它并使它看起来像是单页应用程序的一个很好集成的部分时会遇到问题吗? I've always stayed away from them in the past. 过去我一直都远离他们。

My platform is jQuery, ASP.NET MVC, the usual browsers (plus probably mobile). 我的平台是jQuery,ASP.NET MVC,常用的浏览器(可能还有移动设备)。

在我的情况下,只需将表单发布的目标(包括文件和文本输入)设置为不可见的iframe并监视iframe onload事件,就很容易解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM