0
I’m trying to make a import
file csv
to the MySQL
dealing with errors with JSon
but I’m not succeeding, even with a basic test I can return the message, always falls in the else
of 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’s like this:
$retorno = array('codigo' => 1, 'mensagem' => "RETORNO");
echo json_encode($retorno);
exit();
pUploadImportacaoRH.php is just that one there?
– Julio Henrique
Hello @Juliohenrique, I’m trying for now to see if this script returns me the correct message, already have the upload part, but I’m trying to understand this message.
– adventistapr
right, so put this before echo json_encode. header('Content-Type: application/json');
– Julio Henrique
I put it and it has the same message.
– adventistapr
changes this: (Response.codigo == "1" to that (Response.codigo == 1 . because Voce is comparing string with number
– Julio Henrique