【发布时间】:2023-03-21 13:22:01
【问题描述】:
我有一个包含多个输入的表单以及一个 doc 或 pdf 文件上传。
//Multiple input fields are here then upload ->
<div class="controls">
<div class="fileupload ${ person?.attachment ? 'fileupload-exists' : 'fileupload-new' }" id="attachment" data-provides="fileupload" data-name="attachment">
<span class="btn btn-file">
<span class="fileupload-new">Add</span>
<span class="fileupload-exists">Change</span>
<input type="file" />
</span>
<span class="fileupload-preview"></span>
<a href="#" class="close fileupload-exists" data-dismiss="fileupload" style="float: none">×</a>
</div>
</div>
并且表单是用jquery提交的
$(document).on('click', "#submit", function () {
//TODO Take the chosen file and upload it with form data
//Taking data from form and contructing a object and posting it with ajax
}
当按下#submit 时,我不知道如何使用表单上传 doc/pdf 文件。
客户端上传取自here。
我查看了g:form 和g:uploadForm,但我真的不想使用它们,因为它们似乎会刷新页面和/或重定向用户。
【问题讨论】:
-
你能在控制器端的参数中获取文件对象吗?
-
不,我尝试使用
$("#attachment").find('input')发送它,但这只是对象的标题和长度。