本文介绍了Blue Imps jQuery文件上传以正常字段的形式发送文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以像常规文件上传一样发送带有表单的文件?当我检查文件字段时,该字段始终为空,我需要在一次调用中将其与表单数据一起发送.有可能吗?
Is it possible to send file with form as normal file upload? When I check a file field it is always empty, and I need to send it with form data in one call. IS that possible?
推荐答案
可能会有更好的答案,但是我最终通过执行以下步骤解决了这个问题.
There might be better answers out there, but I ended up solving this by following steps.
- 页面上有2个表单.一种用于文件上传,另一种用于其他表单数据.
- 使用CSS设置两种格式的格式,以便用户获得一种形式的外观.
- 只有一个div(看起来像按钮)可以提交.如果您正在使用它们,则隐藏实际表单的提交按钮(我不这样做,因为我先预处理数据然后通过ajax发送)
- 一旦用户提交表单(通过单击虚拟按钮),就可以使用JS以编程方式单击文件上载按钮.
- 可选.该通话结束后,如果没有错误,则继续.
- 将表单与其他表单数据一起提交.
- Having 2 forms on the page. One for file upload and one for other form data.
- Format both forms using CSS so that user gets look and feel of one form.
- Have only one div (which looks like button) to submit. Hide the actual form's submit button, if you are using them (I don't. Because I preprocess data and then send by ajax)
- Once user submits forms (by clicking the dummy button), Using JS programatically click the file upload button.
- Optional Once that call is finished, if there are no errors only then continue.
- Submit the form with other form data.
我使用这种方法的优势在于,我可以更好地控制用户的表单数据以及文件上载的设置.因为我有一些设置(例如最大文件数和最大文件大小)取决于用户的表单条目.
The advantage I had in this approach was that I could have more control over user's form data as well as my file upload's settings. Because I had some settings (like max number of files and max file size) were dependent on user's form entry.
这篇关于Blue Imps jQuery文件上传以正常字段的形式发送文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!