Function ajax / js does not work [closed]

1

Below is my code, with the function and the field. When testing does not work, I do not know what's wrong. I did this to check if that period already exists in the bank. But I do not even know how to check if the php file is receiving the data or if the result is returning and I'm not displaying correctly.

Thanks in advance for your suggestions.

function verifica(){                  
      var id  = document.getElementsByName("id")[0].value;
      var dt1 = document.getElementsByName("datahora_inicial")[0].value;
      var dt2 = document.getElementsByName("date")[0].value;
      var parametros = {
              method: "GET"
      };
      fetch("php/verifica.php?id=" + id + "&dt1=" + dt1 + "&dt2=" + dt2, parametros).then(function(resposta) {
          return resposta.json();
      }).then(function(retorno){
          console.log(retorno)
          if (retorno == 1) {
            document.getElementById("resultado").value = "Período indisponível! Altere-o.";
            document.getElementById("resultado").style.display = 'inline-block';
            document.getElementById("link").style.display = 'inline-block';
          }else{
            document.getElementById("resultado").style.display = 'none';
          }
      });
  }




<label class="col-sm-2 col-sm-2 control-label">Fim</label>
<div class="col-md-5">
  <input type="text" class="form-control round-input" name="date" required="required" id="dtfim" onchange="verifica();" value="" disabled="disabled">
   <input type="text" class="form-control round-input" id="resultado" disabled="disabled" style="display: none; width: 60px;"><a style="display: none;" href='link.php' id="link">Link</a>                                                            
</div>

php:

header('Content-Type: json/application'); 
$id  = $_GET['id'];
$dt1 = $_GET['dt1'];
$dt1 = date('Y-m-d', strtotime($dt1));

$dt2 = $_GET['dt2'];
$dt2 = date('Y-m-d', strtotime($dt2));

$select    = "SELECT * FROM lista WHERE id = '$id' and start <= '$dt1' and end >= '$dt2'";
$result    = mysqli_query($conexao, $select);

if ((mysqli_num_rows($result) > 0)){
    $mostrar = 1;
    echo json_encode($mostrar); 
}else{
    $mostrar = 2;
    echo json_encode($mostrar);
}
    
asked by anonymous 15.05.2017 / 22:30

0 answers