在网页中上传文件而无需刷新页面 [英] File Uploading without page refresh in Web pages

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

问题描述

Hii

任何人都知道如何将文件上传到服务器的物理位置.有可能使用我知道的文件上传控制.但我想避免页面的外部回发.例如,就像yahoo邮件中所做的一样.

Any one knows how to upload files to the physical location of the server. It is possible using file upload control that i know. But i want to avoid the external postbacking of the page. For e.g exactly like what in the yahoo mail did.

在yahoo mail最新版本中,如果您附加了不会回发的文件并将该文件附加到服务器中.其背后的技术是什么?

In yahoo mail latest version if you attach a file that won't post back and attach that file in to server. What is the technology behind that?

推荐答案

通常,当您提交表单时,它将向服务器发出POST请求,从而导致刷新.Ajax请求通过使用JavaScript将POST数据发送到服务器来解决此问题,而无需刷新页面.

Normally when you submit a form it does a POST request to the server, causing a refresh. Ajax requests get round this by using JavaScript to send the POST data through to the server, and that doesn't need a page refresh.

虽然Ajax请求不能用于发送文件数据,所以当前最好的方法是使用iframe hack-您使用JavaScript在iframe中动态建立表单,通过JavaScript提交该表单,以及监听iframe的onload事件.因此,您知道何时提交表单.此处详细介绍了这种方法的版本:

Ajax requests can't be used to send file data though, so the best way to currently do it is with an iframe hack - you use JavaScript to dynamically build up a form within an iframe, submit that form via JavaScript, and listen for the iframe's onload event. So you know when the form has been submitted. A version of this approach is detailed here:

http://www.webtoolkit.info/ajax-file-upload.html

执行此操作的其他方法包括使用基于Flash的解决方案,例如 http://www.swfupload.org/或类似 http://www.plupload.com/的包装器-这些将阻止您必须推出自己的解决方案,并且还将提供一些额外的功能-例如,上传进度反馈.

Other methods to do this would include using a Flash-based solution like http://www.swfupload.org/ or a wrapper like http://www.plupload.com/ - these will prevent you having to roll your own solution and will also provide some extra functionality - upload progress feedback, for example.

这篇关于在网页中上传文件而无需刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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