I'm trying to make a import
of a file csv
to MySQL
dealing with errors with JSon
but I can not, even with a basic test I can not return the message, it always falls in else
if
.
This is the form:
<form method="post" enctype="multipart/form-data" id="frmImportacao">
<input type="file" name="demo_file" class="file-upload-ajax">
</form>
This is the script:
$(document).ready(function(){
$('.file-upload-ajax').on('change',function(){
$(this).after('<span class="temp-message">Enviado...</span>');
var formdata = new FormData($("#frmImportacao")[0]);
$.ajax({
type: "POST",
url: "ajax/pUploadImportacaoRH.php",
enctype: 'multipart/form-data',
data: formdata,
async: false,
contentType: false,
processData: false,
cache: false,
success: function(response) {
if (response.codigo == "1") {
$("#msgInsert").html('<div class="alert alert-success fade in"><button class="close" data-dismiss="alert">×</button><i class="fa-fw fa fa-times"></i><strong>AVISO!</strong> ' + response.mensagem + '</div>');
} else {
$("#msgInsert").html('<div class="alert alert-danger fade in"><button class="close" data-dismiss="alert">×</button><i class="fa-fw fa fa-times"></i><strong>ATENÇÃO!</strong> ' + response.mensagem + '</div>');
}
}
});
});
});
In php it looks like this:
$retorno = array('codigo' => 1, 'mensagem' => "RETORNO");
echo json_encode($retorno);
exit();