远程文件上传Grails中 [英] Remote File upload in grails

查看:103
本文介绍了远程文件上传Grails中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用Grails它使用大量ajax.I的想用ajax.I不知道如何使用Ajax文件upload.My样本GSP code实现文件的上传web应用是:

I am creating a webapplication using grails which uses lot of ajax.I want to implement file upload using ajax.I dont know how to use ajax for file upload.My sample GSP code is :

<!-- code for file upload form-->
<div id="updateArea">

</div>

我试着用和上传。之后我想更新的updateArea与result.In结果我计划显示上传文件的详细信息。

I tried with and .After uploading I want to update the 'updateArea' with the result.In result I am planning to show details of the uploaded file.

推荐答案

通过Ajax上传的文件是不是真的有可能。您可以使用一个隐藏的iframe仍然在后台上传文件,要么评估repsonse(也就是那么iframe内)或火灾的另一个Ajax调用后上传完成。

Uploading a file via Ajax is not really possible. You can still upload a file in the background using a hidden iframe and either evaluate the repsonse (which is then inside the iframe) or fire another ajax call after the upload is complete.

<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>

另一种选择是使用而不是IFRAME一个基于Flash的上传机制(如: SWFUpload的)。

这篇关于远程文件上传Grails中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆