How to update a div every x seconds?

-2

Following a part of the html code, I need to update this div (# line1) every x seconds without using php. It can be with jquery, ajax, js or all together. I do not want to simply change a div ("altered div"), it is dynamic, it takes data from a controller. I want to give a refresh to reload the data, if you had some insert, delete or update in the database.

<div id="linha1" class="col-md-12">
    <div class="col-md-3">
        <h2>Dados Veículo</h2>
        <table id="tabela">
            <tr>
                <td>Serial</td>
                <td><h:outputText value="#{realtime.serial}" />
                </td>
            </tr>
            <tr>
                <td>Data</td>
                <td><h:outputText value="#{realtime.data}" /></td>
            </tr>
            <tr>
                <td>Hora</td>
                <td><h:outputText value="#{realtime.hora}" /> </td>
            </tr>
            <tr>
                <td>Eixos</td>
                <td><h:outputText value="#{realtime.axlNumber}" /> </td>
            </tr>
            <tr>
                <td>PBT</td>
                <td><h:outputText value="#{realtime.pbt}" /> </td>
            </tr> 
            <tr>
                <td>Classe</td>
                <td><h:outputText value="#{realtime.classe}" /> </td>
            </tr>
            <tr>
                <td>Placa</td>
                <td><h:outputText value="#{realtime.placa}" /> </td>
            </tr>
            <tr>
                <td>Speed</td>
                <td><h:outputText value="#{realtime.speed}" /> </td>
            </tr>

        </table>
    </div>
</div>
    
asked by anonymous 13.09.2018 / 16:39

1 answer

1

Make an ajax call every x seconds and run your code to update the div.

var time = 1000; // 1s

setTimeout(function(){ 
  // Seu código
}, time);
    
14.09.2018 / 14:35