问题
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