在 JQuery 中通过 AJAX 上传文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1686099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:58:54  来源:igfitidea点击:

File Upload via AJAX within JQuery

jqueryajaxfileupload

提问by user200290

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?

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

Thanks, Deepthi.

谢谢,迪普西。

回答by seanmonstar

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

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

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

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

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

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

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

回答by pedro

I had several problems using Uploadify so I turned to ajax upload

我在使用 Uploadify 时遇到了几个问题,所以我转向了ajax 上传

回答by Traveling Tech Guy

Try Uploadify

尝试上传

回答by Jeff Widmer

This is not a jQuery solution but take a look at http://www.swfupload.org. I have used that component in the past to give the ajax / flickr like upload interface. Works great and is fairly easy to integrate into your site. There is a ton of demos at http://demo.swfupload.orgtoo.

这不是 jQuery 解决方案,但请查看http://www.swfupload.org。我过去曾使用该组件来提供类似 ajax/flickr 的上传界面。效果很好,并且很容易集成到您的网站中。http://demo.swfupload.org 上也有大量演示。

回答by John Laniba

I think jQuery Fileuploader Plugin is the best for that. Html5 api is now supported which do the drag and drop and multiple file select. It is platform independent and very easy to install.

我认为 jQuery Fileuploader 插件是最好的。现在支持 Html5 api,它可以进行拖放和多文件选择。它是独立于平台的并且非常容易安装。

http://pixelcone.com/fileuploader/

http://pixelcone.com/fileuploader/