0
I was trying to make a list filter, I would like every time that the select changes its value to update my table, but there’s an error that I can’t find, when starting the page or changing the select no value is returned in my table and is displayed to error Alert.
Index.html
<select id="filtro">
  <option> Alunos </option>
  <option> Professores </option>
 </select> 
 <br> <br>
 <table border="1"> 
    <tr align="center">
       <td> Nome </td>
       <td> Email </td>
       <td> Telefone </td>
       <td> RG </td>
       <td> CPF </td>
    </tr>
    <tr>
       <td id="nome"> </td>
       <td id="email"> </td>
       <td id="tel"> </td>
       <td id="rg"> </td>
       <td id="cpf"> </td>
    </tr>
 </table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
  $(document).ready(() => {
     filtro();
     $('#filtro').change(() => {
        filtro();   
     });   
  });
  function filtro(){
    var data = {
       acao: "filtro",
       filtro: $('#filtro').val(),
    };
    console.log(data);
     $.ajax({
        type: "POST",
        url: "listagem.php",
        dataType: "json",
        data: data,
        sucess: (data) => {
           data = JSON.parse(data);
           $('#nome').html(data.nome);
           $('#email').html(data.email);
           $('#tel').html(data.tel);
           $('#rg').html(data.rg);
           $('#cpf').html(data.cpf);
        }, error: () => {
           alert('Ocorreu algum erro.');    
        }    
     });
  }
</script>
php listing.
include('conexao.php');
$data = $_POST ? $_POST : $_GET;
$response = [
  'error' => ''
];
if(!$data){
   $response['error'] = 'Nada na requisição';
}
if($data['acao'] == 'filtro'){
   $query = "SELECT * FROM login WHERE nivel={$data['filtro']}";
   $result = mysqli_query($con,$query);
   while($row = mysqli_fetch_assoc($result)){
      $response = $row;    
   }
}
return json_encode($response);
"is displayed to error Alert." right, and already tried to see what the error, inspect the message to try to understand the problem? use
}, error: (request, status, error) => {and see what’s in the variables that ajax returns– Ricardo Pontual
the error returned is this: Syntaxerror: Unexpected token < in JSON at position 0, you know tell me what might be?
– Caio Pereira