提交使用AJAX HTML表单,其中包括文件​​输入 [英] Submitting a HTML form with AJAX that includes a file input

查看:162
本文介绍了提交使用AJAX HTML表单,其中包括文件​​输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能提交通过AJAX的形式,有一个文件类型的输入?我试图使用jQuery来做到这一点,但它似乎它不能被序列化提交的文件。这是不是被阻止通过浏览器存在安全问题?有没有变通的办法?

Can you submit a form via AJAX that has a file type input? I am trying to use jquery to do this but it appears that it cannot serialize the file being submitted. Is this something that is blocked by the browser as a security concern? Is there a way around it?

推荐答案

您可以使用文件API ,HTML5的一部分,要做到这一点:

You can use the File API, part of HTML5, to do this:

http://www.html5rocks.com/tutorials/file/dndfiles/

有关它张贴讨论,你可以用

For a discussion on posting with it you can start with

<一个href="http://groups.google.com/group/play-framework/browse_thread/thread/6223a9b25b87a839/6c74eda4f7b33010" rel="nofollow">http://groups.google.com/group/play-framework/browse_thread/thread/6223a9b25b87a839/6c74eda4f7b33010

基本上,使用文件API ,JavaScript可以读取本地系统文件,如果浏览器支持它,然后你可以发布,通过一个Ajax调用,与任何其他你需要提交。

Basically, using the File API, javascript can read files from the local system, if the browser supports it, and then you can just post that through an ajax call, along with whatever else you need to submit.

如果您需要提交多个文件,这可能是一个很好的起点:

If you need to submit multiple files, this may be a good starting point:

<一个href="http://robertnyman.com/2010/04/22/using-the-file-api-for-reading-file-information-multiple-file-uploads-another-sister-specification-to-html5/" rel="nofollow">http://robertnyman.com/2010/04/22/using-the-file-api-for-reading-file-information-multiple-file-uploads-another-sister-specification-to-html5/

如果您必须使用jQuery,那么你可以尝试这个插件,虽然我从来没有使用过:

If you must use jQuery, then you can try this plugin, though I have never used it:

http://plugins.jquery.com/blueimp-file-upload -jquery-UI /

这篇关于提交使用AJAX HTML表单,其中包括文件​​输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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