jQuery验证插件和输入文件的问题 [英] issues with jQuery Validation Plugin and input File
问题描述
我在jQuery Validation Plugin上遇到问题,该输入文件无法通过表单的方法进行确认. 这就是我得到的: myform
I'm having issues with the jQuery Validation Plugin, the input file it's not recongnize by the method of the form. This is what I got: myform
表单的类validate
是我用于初始化插件的类.它有效,它可以验证输入,但是当我单击"Guardar"和print_r('$_FILES');
时,我得到的是array()
.如果我不将类validate
添加到表单中(不要初始化插件),那么我将得到数据,但未进行验证.
我该怎么办?
The class validate
of the form is what I use for initialize the plugin. And it works, it validates the input but when I click on "Guardar" and print_r('$_FILES');
what I get is 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.
What can I do?
推荐答案
Ajax请求无法处理文件输入类型,这就是您未在服务器中获取文件数据的原因.
Ajax requests cannot handle file input type, that is the reason you are not getting the file data in the server.
如果您只想支持html5 FileAPI支持的浏览器,则可以查看此处和此处
If you want to support only html5 FileAPI supported browsers then you can have a look at FormData to submit a file using ajax. You can read more about how to use FormData here and here
var form = document.getElementById('form-id');
var formData = new FormData(form);
$.ajax({
url: '',
data: formData
})
如果要支持跨浏览器,则需要查看类似 jQuery Form 的插件使用iframe模拟ajax之类的表单处理.
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验证插件和输入文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!