简体   繁体   English

用jquery的.post上传文件

[英]Uploading files with jquery's .post

I have form that uploads file's perfectly, with a post-page-refresh-form. 我有一个表格,可以完美地上传文件,并带有页面刷新后的表格。

However I have ajaxiefied the form with jquery's $.post 但是我已经用jQuery的$ .post取消了表单

All of the data except for the file upload is saving nicely. 除文件上传外,所有数据都保存得很好。

Is there somthing special I need to do to the form or in jquery to get the upload to work? 为了使上传正常工作,我需要对表单或jquery做些特殊的事情吗?

Thanks! 谢谢!

You cannot upload with javascript (it would mean granting js file access on your computer, a no go from security standpoint). 您不能使用javascript上传(这意味着要在您的计算机上授予js文件访问权限,从安全角度考虑是不行的)。 Uploadify has a nice solution. Uploadify有一个不错的解决方案。

First off, I agree with Wrikken about Uloadify being a great solution. 首先,我同意Wrikken所说的Uloadify是一个很好的解决方案。

But, yes, Javascript does not have access to upload files. 但是,可以,Javascript无法访问上传文件。 There is a way around this by using Flash, but I would not go through all the trouble to build it yourself when there are other plugins out there that will take care of it all for you. 使用Flash可以解决此问题,但是当有其他插件可以为您解决所有麻烦时,我不会自己动手构建它。

You can make it "lookalike" AJAX. 您可以将其设为“相似” AJAX。 Use a hidden iframe and send your form into this iframe, you will be able to observe the onload of the iframe and get a response. 使用隐藏的iframe并将表单发送到该iframe中,您将能够观察iframe的加载情况并获得响应。

This way gives you also the option for an easy fallback if JS is disabled. 如果禁用了JS,这种方式还为您提供了一个简单的后备选项。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM