How to update a div every x seconds?

Asked

Viewed 1,263 times

-2

Follow 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 don’t want to just change a div ("altered div"), it’s dynamic, it takes data from a controller. I want to give a refresh to reload the data, in case you had any 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>
  • 1

    If you understand English, here is the answer: https://www.brightcherry.co.uk/scribbles/jquery-auto-refresh-divevery-x-seconds/

  • 1

    have you thought about using setTimeout?

  • This one in Portuguese, if you did a little research, it already had the resolution... https://answall.com/questions/178662/upr-div-automaticamente-autorefresh-sem-update-p%C3%A1gina-toda

  • Yeah, I’ve followed that topic already, but it doesn’t carry the div only, it carries the whole page, I don’t know what I’m doing wrong

1 answer

2

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);

Browser other questions tagged

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