简体   繁体   English

通过ajax post(jQuery)发送输入类型=“文件”表单数据

[英]Send input type=“file” form data via ajax post (jQuery)

I want to send the post data from an input like this: 我想从这样的输入发送帖子数据:

<input type="file" name="userFile" id="userFile"/>

?

I need to send it via ajax using $.post to a specified file. 我需要使用$ .post通过ajax将其发送到指定文件。

How can I do this? 我怎样才能做到这一点?

Without HTML5, this isnt possible, and the html5 solution won't work in all browsers without workarounds for browsers that don't support it. 没有HTML5,这是不可能的,并且如果没有不支持HTML5的浏览器的解决方法,则html5解决方案将无法在所有浏览器中使用。

The most cross-browser way to solve this is to not use ajax and to instead post to a hidden iframe. 解决此问题的最跨浏览器的方法是不使用Ajax,而是发布到隐藏的iframe。

Or use a plugin such as uploadify . 或者使用插件,例如uploadify

Most if not all of the jQuery plugins that implement this use either flash or hidden iframes when the html5 method isn't supported. 当不支持html5方法时,大多数(如果不是全部)实现此功能的jQuery插件都使用Flash或隐藏的iframe。

使用jquery.form插件...

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

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