7
<script type="text/javascript">
$(function(){
$("#oformulario").submit(function(e){
e.preventDefault();
var nome = $("#nome").val();
var email = $("#email").val();
var obs = $("#obs").val();
var file0 = $("#file0").val();
var file1 = $("#file1").val();
if( (nome == "" || nome == null) ||
(email == "" || email == null) ||
(file0 == "" || file0 == null) ){
alert("Preencha todos os campos obrigatórios.");
return false;
} else {
// Ajax
}
});
});
</script>
I want to send #file0 and #file1 which are files (input[type=file])
by ajax for PHP.
Take a look at the file submission section with the
FormData
: https://developer.mozilla.org/en-US/docs/Web/Guide/Using_FormData_Objects. OFormData
belongs to theXMLHttpRequest 2
and the table of supported browser versions is here: http://caniuse.com/#feat=xhr2 (in particular IE8 and IE9 do not support).– Wakim