在 JQuery 中通过 AJAX 上传文件 [英] File Upload via AJAX within JQuery

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

问题描述

我是 JQuery AJAX 的新手.我想使用 jquery 实现文件上传.是否可以使用JQuery,AJAX进行文件上传并将其发送到可以使用apache文件公共上传文件的Servlet.任何人都可以请教我如何进一步处理吗?

I am new to JQuery AJAX . I want to implement a file upload using a jquery. Will it be possible to make a fileupload with JQuery,AJAX and send it to Servlet which can use apache file commons to upload the file. Can anyone please advice me how to proceed further?

谢谢,深度.

推荐答案

传统意义上的 Ajax 是 XMLHttpRequest,它不允许您对本地文件进行编码并将其发送到服务器.

Ajax in the traditional sense is XMLHttpRequest, which does not allow you encode and send local files to a server.

通过ajax"方式进行上传的常见方式,是使用 Flash swf 处理同一页面上的上传,或者使用具有不可见 1x1 iframe 目标的表单强>.您有一些 Javascript 显示上传微调器或任何其他内容.文件上传后,让服务器像

The common ways of doing uploading through "ajax" means, is to either use a Flash swf to handle the uploading on the same page, or to use a form that has a target of an invisible 1x1 iframe. You have some Javascript show a uploading spinner or whichever. After the file is uploaded, make the server return some Javascript to the iframe like

<script type="text/javascript">
top.MyProject.doneUploading();
</script>

top 将允许您在常规页面中调用 Javascript.但是,为了使其正常工作,您必须确保 iframe 已提交到顶级文档所在的域.

top will allow you to call Javascript in the regular page. In order for that to work though, you must make sure the iframe has submitted to the same domain that the top document is located at.

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

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