文件上传使用AJAX文件上传、AJAX

2023-09-10 15:50:56 作者:潙你丶颠覆葰有

我要寻找一个AJAX方法,该方法可用于文件上传。 这将是超级,如果我发现使用原型+ Script.acul.us功能

I am looking for an AJAX method that can be used to file upload. It will be super if I find a function that uses Prototype + Script.acul.us

推荐答案

正如其他人所指出的那样,JavaScript是不能够异步上传文件(否则启用JavaScript的网站可以窃取任何文件,关闭你的硬盘)。最好的方法是:

As others have pointed out, javascript is not able to asynchronously upload files (otherwise javascript enabled sites could steal any file off your harddrive). The best approaches are:

闪存上传,因为已经建议 或者使用iframe模拟一个Ajax请求

iframe的做法意味着它,而不是展示给用户的页面,该页面重新加载的iframe,使最终用户,体验看起来好像是阿贾克斯。

The iframe approach means that it's the iframe which reloads, instead of the page displayed to your users, so that to the end user, the experience looks as if it's Ajax.

如果您使用的是轨道,这是我收集你可能是由于使用的原型和Scriptaculous,有它处理这种方法的棘手位你打电话的 responds_to_parent ,它已经老化,因为我在Rails实现这个程序,我自己,但从这个博客看起来像如何使用它的一个很好的例子,第6步。

If you're using rails, which I gather you might be due to using prototype and scriptaculous, there's a plugin available which handles the tricky bits of this approach for you called responds_to_parent, It's been ages since I implemented this in a rails app myself, but step 6 from this blog looks like a good example of how to use it.