简体   繁体   English

如何进行文件上传并将结果返回到同一页面?

[英]How can I do a File Upload and return results to the same page?

I need to do a file upload and return the results to the same page. 我需要上传文件,并将结果返回到同一页面。 The <form> also has a couple of data fields that will be sent in the POST. <form>还具有几个将在POST中发送的数据字段。

I can't use HTML 5 due to limited browser support, and unfortunately the AJAX file upload solutions I've seen all use HTML 5. I could do the POST in Javascript but I haven't seen a file upload done like this. 由于浏览器支持有限,我无法使用HTML 5,不幸的是,我看到的所有AJAX文件上传解决方案都使用HTML5。我可以使用Javascript执行POST,但没有看到这样的文件上传。

My server is written in Java but that shouldn't matter. 我的服务器是用Java编写的,但这无关紧要。

Is there a way to get the results of this kind of POST to return to the same page? 有没有办法让这种POST结果返回到同一页面?

I would suggest you take a look at how the jQuery Form Plugin does "legacy" file uploads. 我建议您看一下jQuery Form Plugin如何完成“旧版”文件上传。 Basically it uses an iframe to submit the form in the background. 基本上,它使用iframe在后台提交表单。 http://malsup.com/jquery/form/#file-upload http://malsup.com/jquery/form/#file-upload

The generally accepted method outside of Flash, Silverlight, and the HTML5 File API, is to have your <form> post to an invisible <iframe> on the page. Flash,Silverlight和HTML5 File API之外的公认方法是将<form>发布到页面上不可见的<iframe>上。

The <iframe> location is the page or file handler that uploads your file under the hood. <iframe>位置是在后台上传文件的页面或文件处理程序。 You then have a javascript function running on the main page, that polls your server periodically and checks to see if the download has been completed. 然后,您将在主页上运行一个javascript函数,该函数会定期轮询服务器并检查下载是否已完成。

When you upload the file to the <iframe> , you need some way of identifying the upload that both the client and server know. 将文件上传到<iframe> ,需要某种方式来识别客户端和服务器都知道的上传。 One way to do this is to generate a GUID on the client, and post it along with the file and your other data fields. 一种方法是在客户端上生成一个GUID,并将其与文件和其他数据字段一起发布。 The server should keep hold of that GUID before receiving the file data and track the progress of the upload by linking the progress and the GUID together. 在接收文件数据之前,服务器应保留该GUID,并通过将进度和GUID链接在一起来跟踪上载进度。 Since the client generated already knows the GUID, it can send requests to the server to get the progress of that upload by sending the what it generated. 由于生成的客户端已经知道GUID,因此可以通过发送生成的内容向服务器发送请求,以获取上载的进度。

I ended up using the jQuery Form Plugin . 我最终使用了jQuery Form Plugin It supports sending basic auth credentials in the header with this option: 它支持使用此选项在标头中发送基本身份验证凭据:

headers  : { Authorization: basicAuthCredentials}

which I also need to do. 我也需要做

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 laravel 中上传文件后如何返回与所选数据相同的页面 - How to return to same page with selected data after file upload in laravel 在 javascript 中上传之前如何处理图像预览? 代码不能在同一页面上工作两次 - How do I handle image preview before upload in javascript? The code can't work twice on the same page WordPress:我可以启动在同一页面上声明的小型javascript吗? 或如何将.js文件上传到Wordpress? - Wordpress: can I launch a small javascript declared on the same page? Or how to upload .js file to Wordpress? 如何在同一页面上显示图像输入结果? - How do I display image input results on same page? 提交表单(过滤内容)后,结果表将显示在同一页面上。 我怎么做? - After submitting a form (to filter content), the table of results appear on the same page. How do I do that? 如何在类中返回.query的结果 - How do I return the results of .query in a class 如何使用javascript刷新页面内容并返回同一页面 - How do i refresh the contents of a page and return to the same page using javascript 如何在同一页面的iframe元素中显示Word文件? - How can i show word file in iframe element in same page? 我如何把这个结果放在同一行 - How do I put this results on the same row 如何将后端查询的结果返回到前端以显示在页面上 - How can I return the results of my backend Query onto my frontend to display on a page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM