Error when making real time request with Xmlhttprequest

Asked

Viewed 48 times

-1

I have an error in my Real Time request via Xmlhttprequest, follow javascript code:

function requisitar() {
    var base_url = window.location.origin;

    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest();
    } else
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function ()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
           document.getElementById("solicitacao_mesas").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", base_url + "/modulos/lista_solicitacao_mesas.php", true);
    xmlhttp.send();
}     
window.setInterval(requisitar, 1000);

Now follow my PHP:

header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
include_once($_SERVER['DOCUMENT_ROOT'] . '/conexao/conecta.php');

$read = new Read;
$read->ExeRead("ws_notificacao");
if ($read->getResult()) {
foreach ($read->getResult() as $mesa) {

    $read->ExeRead("ws_users", "where user_id = :id", "id={$mesa->user_id}");
    if ($read->getResult()) {
        $user = $read->getResult()[0];
    }

    if ($mesa->status == 0) {
        echo "<audio style=\"display:none;\" autoplay=\"autoplay\" controls=\"controls\">
                <source src=\"{$base}/images/alert.mp3\" type=\"audio/mp3\" />
                Seu navegador não suporta HTML5
            </audio>";
        $btn = "<a class=\"btn btn-success btn-md btn-flat aceitar\" data-id=\"{$mesa->notificacao_id}\">Aceitar</a>&nbsp;<a class=\"btn btn-danger btn-md btn-flat rejeitar\" data-id=\"{$mesa->notificacao_id}\">Rejeitar</a>";
    } else {
        $btn = "";
    }
    $data = date('d/m/Y', strtotime($mesa->data));
    $hora = date('H:i:s', strtotime($mesa->hora));
    echo "<tr><td>{$mesa->notificacao_id}</td><td>{$mesa->mesa_id}</td><td>{$user->user_name} {$user->user_lastname}</td><td>{$data}</td><td>{$hora}</td><td>{$btn}</td></tr>";
}}

The error that is returned:

<b>Parse error</b>:  syntax error, unexpected 'endif' (T_ENDIF) in <b>/app.artcomacucar.com.br/modulos/lista_solicitacao_mesas.php</b> on line <b>21</b><br />
  • What is line 21?

  • To be honest, it seems to me that it has something to do with the cache, more from the beginning the line 21 was the end of Else{ -> } <-, but now I have already made changes and this end, is no longer on line 21, and keeps returning me the error on line 21, I need to correct this cheap.

  • Where are you wearing endif?

  • In the variable $btn which generates the link (<a href...) you used "keys" {value} directly, try using dots and double quotes. For example, instead of: ; data-id=\"{$mesa->notificacao_id}\" Like this: data-id=\"".{$mesa->notificacao_id}."\" ?

  • Hello friends, I was checking and I came to the conclusion that the code was not wrong, the problem was cache, simply, I created a new file, copied the code of the file that was with the problem, and changed the request URL, it worked right, will be the tip there, why go through the same problem.

1 answer

-1

I was checking and came to the conclusion that the code was not wrong, the problem was cache, I simply created a new file, copied the code of the file that was with the problem, and I changed the request URL, it worked fine, will be the tip there, why go through the same problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.