远程文件上传Grails中文件上传、Grails

2023-09-10 13:18:15 作者:視覺、別越軌

我创建使用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的)。

 
精彩推荐