我是 grails 框架的新手,我遇到了以下问题:
- 我想上传带有文件和一些细节的项目,比如标题、描述,我有非常大的 stl 3d 文件。虽然文件上传需要时间,但我希望用户进入下一页并填写项目其余详细信息,如标题描述等。
我无法弄清楚我将如何做到这一点..我看过 grails aynch 编程,但我无法弄清楚如何实现它。
如果有人对此提供指导,我将不胜感激
我是 grails 框架的新手,我遇到了以下问题:
我无法弄清楚我将如何做到这一点..我看过 grails aynch 编程,但我无法弄清楚如何实现它。
如果有人对此提供指导,我将不胜感激
不久前,我处理了一个包含文件上传的表单,我想异步完成。花了很多谷歌搜索,不幸的是我不记得我使用的任何参考资料,但这是我最终做的。
我在文件输入上包含了一个Onchange属性,该属性在选择文件时会调用JavaScript函数以验证和上传文件异步。
文件输入:
<input type="file" name="uploadMedical" id="uploadMedical" onchange="validateAndUpload(this, $(this));" accept=".pdf,.jpg,.jpeg" multiple>
JavaScript(我尽我所能去除与您的问题无关的代码,同时仍然留下足够的内容来帮助解决您的问题):
function validateAndUpload(input, documentInput){
var uploadForm = $("#uploadForm");
// Stop the browser from submitting the form.
uploadForm.submit(function(event) {
event.preventDefault();
});
// Get the selected files from the input.
var files = input.files;
// Create a new FormData object.
var formData = new FormData();
// Loop through each of the selected files.
for (var ii = 0; ii < files.length; ii++) {
var file = files[ii];
// Add the file to the request.
formData.append('supportingDocumentation', file, file.name);
}
//Include ID of record to associate this upload with
formData.append('id', getAppealId());
// Submit the form using AJAX.
$.ajax({
type: 'POST',
dataType : "html",
url: url_str,
data: formData,
processData: false,
contentType: false,
beforeSend:function(){
//indicate that the file is uploading
},
success:function(htmlData){
//display the new list of files on the page
},
error:function(ee){
//indicate that the upload failed
},
complete:function(){
//reset the file input so more files can be uploaded
}
})
}