issues with jQuery Validation Plugin and input File

空扰寡人 提交于 2019-12-13 03:13:36

问题


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

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?


回答1:


Ajax requests cannot handle file input type, that is the reason you are not getting the file data in the server.

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
})

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.



来源:https://stackoverflow.com/questions/18928318/issues-with-jquery-validation-plugin-and-input-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!