0
I am the following javascript to reload a div every 30 seconds, but it’s not working , or error. 
Code:
$(document).ready(function() {
    var $div_novospedidos = $('#div_novospedidos');
    $div_novospedidos.empty(); //Limpando a tabela
    //setTimeout(function(){ location.reload(); }, 30000);
    setTimeout(newRequests(), 30000);
    function newRequests() {
        //$div_novospedidos.load("database3.php", function(data, status){
        $.get("database3.php", function(data, status) {
            var dados_pedido = data;
            const obj = dados_pedido;
            function executa_new() {
                try {
                    var dados = JSON.parse(data);
                    console.log(dados);
                    $.each(dados, function(i, item) {
                        numeroPedido = item.doc_number;
                        nomeCliente = item.client_name;
                        horarioPedido = item.clock;
                        var newReq = $('<div class="panel panel-default col-6 col-lg-4 ">');
                        var cols = "";
                        cols += '<p>HORARIO: ' + horarioPedido + '</p></div>';
                        cols += '<p>PEDIDO: ' + numeroPedido + '</p></div>';
                        cols += '<p>Cliente: ' + nomeCliente + '</p></div>';
                        newReq.append(cols);
                        $("#div_novospedidos").append(newReq);
                    });
                } catch (e) {
                    if (typeof dados != 'undefined') {
                        alert('Ocorreu um erro durante a chamada ' + e);
                    } else {
                        var zeroReq = $('<div class="panel panel-default col-6 col-lg-4 "><h1>SEM NOVOS PEDIDOS</h1>');
                        $("#div_novospedidos").append(zeroReq);
                    }
                }
            }
            if (typeof dados != 'undefined') {
                alert("SEM PEDIDOS");
            } else {
                executa_new();
            }
        });
    }
});
There’s only one call
setTimeoutso it’ll never be every 30 seconds, and you’re usingif (typeof dados != 'undefined') {out of functionexecuta_new()where thedadosis defined.– Isac
and what correction ?
– Rodrigo Bravo
Exchange the
setTimeoutforsetIntervalto see what happens. I don’t understand why one function inside the other.– Sam
Also I could not understand the idea of function
executa_newinside ajax if it is not executed immediately or stored in a variable. It would be better to remove this function and leave only the code it has.– Isac