如何轻松上传文件,而无需提交表单(使用jQuery + AJAX)

问题描述:

所以我有某种形式的处理code的处理标准文本输入,并上传的文件(通过$ _FILES数组)

So I have some form processing code which processes the standard text inputs and also uploaded files (through the $_FILES array)

我想已经提交通过AJAX做

I want to have the submission done through AJAX

请问jQuery的岗位()。方法还通过这些东西通过 - > $ _FILES或做我需要做一些特别的东西。

Will jQuery's post(). method still pass that stuff through -> $_FILES or do I need to do something special?

阿贾克斯(定义,使用JavaScript)不能完成文件上传,因为JavaScript不能访问本地文件系统。有解决方法,似乎使用Ajax,比如iframe或使用Flash。

Ajax (as defined, using JavaScript) cannot perform file uploads, as JavaScript cannot access the local filesystem. There are workarounds that seem to use Ajax, such as an iframe or using Flash.

围绕谷歌亨特,你会发现一些东西。还有更多的库(YUI例如),它们把这个在一起。

Hunt around Google, you'll find something. There are more libraries (YUI for example) that are putting this together.