My jQuery is not able to work the json it received from the back

0

Well, I've been trying to sort this out since yesterday. Well I'm doing an ajax request for my backend. So far so good, the data comes in and runs right, they do what I want. I return an array converted to Json. When I get into my jQuery, I can not use it as an object. It always gives the same error "Uncaught SyntaxError: Unexpected end of JSON input" or simply goes empty. Help me please ...

This is Ajax.

$('.inicia-chat').click(function(){
$('#destinatario').val('24');
$.ajax({
    url: 'php/carrega-chat.php',
    type: 'POST',
    data:{
      'destinatario' : 24
    }
  }).done(function(dados_array){
    var parse = JSON.parse(dados_array);
    console.log(parse);
  });
});

This is PHP

$conn = new mysqli('localhost', 'root', '', 'kashikoi');
   if ($conn->connect_error) {
       $erro = '<script>alert('.$conn->connect_error.')</script>';
   }

$consulta_mensagem = "select * from mensagem where id_destinatario = ".$destinatario."";
$consulta_m = $conn->query($consulta_mensagem);

$rows = $consulta_m->num_rows;

$array = array();

if($rows <= 0){
    echo 1;
}else{
    while($linha = $consulta_m->fetch_array(MYSQLI_ASSOC)){
        $wow = array($linha['id_destinatario'], $linha['id_remetente'], $linha['mensagem']);
        array_push($array, $wow);
    }

    echo json_encode($array);
}
    
asked by anonymous 10.06.2017 / 14:01

0 answers