Ajax Requests

0

I have a form and it is a field in which the user can select a professional for the desired service, and when selecting such service I have to inform the available timetables by making an ajax request using a select script in my database taking the supposed schedules that are already filled by the professional and so use the JS to filter and expose the user only the available schedules, but is giving error. Follow the code.

function buscarHorarios(dataConsu)
{
  $.ajax({
      url: 'select2.php', // declarando o script que vai conter os dados
      type: 'POST',
      async: true,
      dataType: 'json', // o tipo de arquivo de cambio que vai ser na usado na requisição
      data:{'dataConsu': dataConsu}, 

      success: function (resultado, xhr, status)
      {
        if (resultado.statusText == "OK")
        {
          var size = resultado.responseText[0].length;
          var resp = JSON.parse(resultado.responseText);

          document.getElementById("uhoraConsult").innerHTML = "<option></option>";

          if (resp.resp == false)
          {
            for (var i = 8; i < 18; i++)
            {
              document.getElementById("uhoraConsult").innerHTML += '<option value="'+ i +'">' + i + ':00</option>';
            }
          }
          else
          {
            var t;
            for (i = 8; i < 18; i++)
            {
              t =false;
              for (var j = 0; j < size; j++)
              {
                if (resposta[0][j].Horario == i)
                {
                  t = true;
                }
                if (t == false)
                {
                  document.getElementById("uhoraConsult").innerHTML += '<option value="'+ i +'">' + i + ':00</option>';
                }
              }
            }
          }
        }
},
      error: function (xhr, error, status)
      {
        alert (xhr.statusText + error + status);  
      }
  });
}

* I have an error that I have been able to catch in an alert: OKparsererrorSyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data

*

<?php

require_once "conexao01.php";
class Horarios
{
    public $hora1;
    public $hora2;
}

    $connecting = conectaAoMySql(); // estabelecendo conexao com o banco de dados

    $vetorHorario = []; // declarando vetor como nulo

    $dataConsulta = $medico = "";

    if(isset($_POST["dataConsu"]))
        $dataConsulta = $_POST["dataConsu"];

    if(isset($_POST["medico"]))
        $medico = $_POST["medico"];

    $SQL = "
        SELECT Horario
        FROM Agenda 
        WHERE DataConsulta = '$dataConsulta'
        AND Medico = '$medico'
    ";

    if (!$resultadoSQL = $connecting->query($SQL))
        throw new Exception ("Ocorreu uma falha: ". $connecting->error);

    if ($resultadoSQL->num_rows > 0)
    {

        while ($row = $resultadoSQL->fetch_assoc())
        {
            $vetorHorario [] = $row ["Horario"];
        }

        $vsf = json_encode($vetorHorario);
        echo $vsf;
    }
?>
    
asked by anonymous 03.06.2018 / 18:50

0 answers