简体   繁体   English

jQuery验证插件和输入文件的问题

[英]issues with jQuery Validation Plugin and input File

I'm having issues with the jQuery Validation Plugin, the input file it's not recongnize by the method of the form. 我在jQuery Validation Plugin时遇到问题,该输入文件无法通过表单的方法进行确认。 This is what I got: myform 这就是我得到的: myform

The class validate of the form is what I use for initialize the plugin. 表单的类validate是我用于初始化插件的内容。 And it works, it validates the input but when I click on "Guardar" and print_r('$_FILES'); 它有效,它可以验证输入,但是当我单击“ Guardar”和print_r('$_FILES'); what I get is array() . 我得到的是array() If I don't add the class validate to the form (Don't intialize the Plugin) then I get the data but without validation. 如果我不将类validate添加到表单中(不要初始化插件),那么我将获得数据但未进行验证。 What can I do? 我能做什么?

Ajax requests cannot handle file input type, that is the reason you are not getting the file data in the server. Ajax请求无法处理文件输入类型,这就是您未在服务器中获取文件数据的原因。

If you want to support only html5 FileAPI supported browsers then you can have a look at FormData to submit a file using ajax. 如果您只想支持html5 FileAPI支持的浏览器,则可以查看FormData以使用ajax提交文件。 You can read more about how to use FormData here and here 您可以在此处此处阅读有关如何使用FormData的更多信息。

var form = document.getElementById('form-id');
var formData = new FormData(form);
$.ajax({
   url: '',
   data: formData
})

If you want to support cross browser then you need to look at a plugin like jQuery Form which simulates a ajax like form handling using iframes. 如果要支持跨浏览器,则需要查看类似jQuery Form的插件,该插件可模拟ajax,例如使用iframe处理表单。

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

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