I have a form with 3 fields being one of type file. Validation works perfectly. When I try to send data using ajax, I get the error: "SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data".
When checking with the browser debug it displays this in "params":
----------------------------- 147651797215788 Content-Disposition: form-data; name="archp"; filename="100_1369.JPG" Content-Type: image / jpeg
ÿØÿáBàExif (several characters of this type)
I tried in many other ways, searching the net, but it did not work out at all.
This is the script:
$("#formAgendaConsulta1").validate({
// Define as regras
unkeyup: false,
rules:{
arqup:{
required: true
},
especialidade:{
required: true
},
especialista:{
required: true
},
dataConsulta:{
required:true,
dateBR:true
},
horaConsulta:{
required:true,
timeBR:true
}
},
submitHandler: function( form ){
//var dados = $( form ).serialize();
var dados = new FormData($(this)[0]);
$.ajax({
type: "POST",
url: $( form ).attr('action'), // "saveAgendaConsulta1.php",
data: dados,
processData: false,
contentType: false,
dataType: "json",
success: function( data ){
var msgFinal = data.msgFinal;
$('#resultAgendaConsulta1').html( msgFinal );
$('#resultAgendaConsulta1').show( 'slow' );
},
beforeSend: function(){
$('#loadAgendaConsulta1').css({display:"block"});
},
complete: function(msg){
$('#loadAgendaConsulta1').css({display:"none"});
},
error: function(){
bootbox.alert("Falha de Conexão!<br />Não foi possível efetuar sua requisição.<br/>Aguarde alguns instantes e faça uma nova tentativa.");
}
});
return false;
}
});