Don*_*onX 6 ajax grails frameworks asyncfileupload
我正在使用grails创建一个web应用程序,它使用了大量的ajax.我想用ajax实现文件上传.我不知道如何使用ajax进行文件上传.我的示例GSP代码是:
<!-- code for file upload form-->
<div id="updateArea">
</div>
Run Code Online (Sandbox Code Playgroud)
我试过和.上传后我想用结果更新'updateArea'.结果我打算显示上传文件的详细信息.
通过 Ajax 上传文件实际上是不可能的。您仍然可以使用隐藏的 iframe 在后台上传文件,并评估响应(然后在 iframe 内)或在上传完成后触发另一个 ajax 调用。
<g:form name="upload-form" action="upload" method="post" enctype="multipart/form-data" target="hidden-upload-frame">
File: <input type="file" name="myFile" />
<button type="submit">Upload</button>
</g:form>
<iframe id="hidden-upload-frame" name="hidden-upload-frame" style="display: none" onload="onUploadComplete">
</iframe>
<script type="text/javascript">
function onUploadComplete(e) {
// Handle upload complete
alert("upload complete");
// Evaluate iframe content or fire another ajax call to get the details for the previously uploaded file
}
</script>
Run Code Online (Sandbox Code Playgroud)
另一种选择是使用基于 Flash 的上传机制(例如swfupload)而不是 iframe。
归档时间: |
|
查看次数: |
8625 次 |
最近记录: |