Create clock online - Automatic generation

0

I have the following code:

<script type="text/javascript">
            $.ajax({
                type      : 'post', 
                url       : 'menu.php', 
                // data      : 'nome='+ $('#hora').val(), 
                dataType  : 'html', 
                success : function(resultado){
                        $('#hora').html(resultado);
                    }
            });
        </script>

<div id="hora">
            <label>
            <?php setlocale( LC_ALL, 'pt_BR', 'pt_BR.iso-8859-1', 'pt_BR.utf-8', 'portuguese' ); 
                        date_default_timezone_set( 'America/Fortaleza' );
                        echo date('H:i:s'); ?>
                    </label>
                    </div>

The problem I have is to update the clock by itself without refreshing the page. At the moment I can update the clock, but it opens the same full page in the code, as shown in the following image:

Andmostofthetimeitevencrashes,andwhenitdoesnotcrashwhenclickingononeoftheoptionsthepageisnotdirectedtoanotherpage,somyguessisupdatingtoo.

Fullhtmlcode:

<!DOCTYPEhtml><html><head><metahttp-equiv="Content-Type" content="text/html" charset="utf-8">
        <title>Menu</title>
        <link rel="icon" type="img/png" href="img/Brasão_do_Ceará.png">
        <link rel="stylesheet" type="text/css" href="./css/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="css/estilo_menu.css">
        <link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
        <script type="text/javascript" src="./jquery/jquery.min.js"></script>
        <script type="text/javascript" src="./jquery/bootstrap.min.js"></script>
        <script type="text/javascript">
            $.ajax({
                type      : 'post', 
                url       : 'menu.php', 
                // data      : 'nome='+ $('#hora').val(), 
                dataType  : 'html', 
                success : function(resultado){
                        $('#hora').html(resultado);
                    }
            });
        </script>
</head>
    <body>
        <div id="hora">
        <label>
        <?php setlocale( LC_ALL, 'pt_BR', 'pt_BR.iso-8859-1', 'pt_BR.utf-8', 'portuguese' ); 
                    date_default_timezone_set( 'America/Fortaleza' );
                    echo date('H:i:s'); ?>
                </label>
                </div>
        <h1>Coga</h1>
        <div class="caixa" id="ocorrencia" title="Adicionar Ocorrência." onclick="window.location = 'index.php';">
        <i class="glyphicon glyphicon-plus-sign"></i>
        <br>
        <h4>Adicionar Ocorrência</h4>
        </div>
        <div class="caixa" id="edita_ocorrencia" title="Editar Ocorrência." onclick="window.location = 'editar_ocorrencia.php';">
        <i class="fa fa-pencil-square-o fa-5x"></i>
        <br>
        <h4>Editar Ocorrência</h4>
        </div>
        <div class="caixa" id="usuario_edit" title="Alteração de Login ou Senha!" onclick="window.location = 'editar_usu.php';">
        <i class="fa fa-address-card fa-5x"></i>
        <br>
        <h4>Edição de Acesso</h4>
        </div>
        <div class="caixa" id="relatorio" title="Gerar Relatório." onclick="window.location = 'relatorio.php';">
        <i class="fa fa-bar-chart-o fa-5x"></i>
        <br>
        <h4>Gerar Relatório</h4>
        </div>
        <div class="caixa" id="usuarios" title="Gerenciamento de Usuários" onclick="window.location = 'gerencia_usuarios.php';">
        <i class="fa fa-user fa-5x"></i>
        <br>
        <h4>Gerenciamento de Usuários</h4>
        </div>
        <div class="caixa" id="sair" title="Sair." onclick="window.location = 'sair.php';">
        <i class="glyphicon glyphicon-log-out"></i>
        <br>
        <h4>Sair</h4>
        </div>
    </body>
</html>

I need help, thanks!

    
asked by anonymous 14.09.2017 / 05:38

1 answer

0

See what's coming up in your callback , it seems like instead of returning the updated time you're returning the entire html of menu.php . I would also recommend cleaning the div before upgrading, this will ensure nothing doubles.

$('#hora').html("").append(resultado);
    
14.09.2017 / 19:20