Update of DIV

Asked

Viewed 112 times

1

Hello, I have a small project just for Hobbie, and I have some Datatables on my web page, to facilitate the search of registered data, but when I register any data in a Brownser tab, the other one does not appear unless I give a refresh/Reload/F5 on the page, how would I automate this "refresh"?

<div class="tab-pane" id="tab7">                    
<div class="content-box-large">
    <div class="panel-heading">
        <div class="panel-title">Área de Serviço</div>
        <div class="panel-options">
            <a href="#" data-rel="collapse"><i class="glyphicon glyphicon-refresh"></i></a>
        </div>
    </div>
    <div class="panel-body panel-refresh" id="refresh4">
        <div class="refresh-data">
            <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example4">
                <thead>
                    <tr>
                        <th>Código</th>
                        <th>Área de Serviço</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                        $consultar_area_servico = "SELECT * FROM `$tabela_area_servico`";
                        $resultado_consultar_area_servico = mysql_query($consultar_area_servico);
                        $quantidade_resultado_area_servico = mysql_num_rows($resultado_consultar_area_servico);
                        for($i = 0;$i < $quantidade_resultado_area_servico; $i++)
                        {
                            $vetor_area_servico = mysql_fetch_array($resultado_consultar_area_servico);
                    ?>
                    <tr class="gradeA">                                         
                        <td><button type="button" class="btn btn-default btn-block btn-xs" data-toggle="modal" data-target="#myModalAS<?php echo $vetor_area_servico['codigo'];?>"><?php echo $vetor_area_servico['codigo']; ?></button></td>
                        <td><input class="form-control"   type="text" name="c_area_servico" value="<?php echo $vetor_area_servico['area_servico']; ?>"></td>
                    </tr>

                    <div class="modal fade" id="myModalAS<?php echo $vetor_area_servico['codigo'];?>" role="dialog">
                        <div class="modal-dialog">
                            <!-- Modal content-->
                            <div class="modal-content">
                                <form action="web/acoes.php" method="post">
                                    <input type="hidden" name="confirma" value="8">
                                    <input type="hidden" name="c_cod" value="<?php echo $vetor_area_servico['codigo'];?>">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                                        <h4 class="modal-title">#<?php echo $vetor_area_servico['codigo'];?></h4>
                                    </div>
                                    <div class="modal-body">
                                        <p>Área de Serviço:<input class="form-control"  type="text" name="c_area_servico" value="<?php echo $vetor_area_servico['area_servico']; ?>"></p>
                                        <center>
                                            <button type="submit" name="button" value="1" class="btn btn-danger btn-sm">Excluir</button>
                                            <button type="submit" name="button" value="2" class="btn btn-success btn-sm">Alterar</button>
                                        </center>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <?php
                        }
                    ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

  • Update only the entire page or div ?

  • mysql is obsolete in recent versions of php, use mysqli.

  • A better solution than a refresh (although much more laborious) is to make an ajax request of X in X time and change the page based on what you receive in that request

  • I wanted to update all Divs that have a Datatable, but unfortunately it will not be possible to escape from Ajax ;-;

  • You have to make an Ajax, as you put in the tags yourself.

1 answer

-1

If you have two tabs open for the same system and made an Insert in one of them. You can’t control the other open tab, just the one with the focus. What could do if this was the case is to put an autorefresh from time to time on your page. Or maybe I didn’t understand your question correctly. If it is the case of autorefresh just insert in your javascript of the page you want to refresh the code below.

setTimeout(function(){
   window.location.reload();
}, 5000); //vai atualizar a página de 5 em 5 segundos
  • Evandir, you got it wrong. The operation it needs is similar to what we find here on the site, when we receive a positive vote for example we earn +10 points and we know this without even need to give a refresh on the page.

Browser other questions tagged

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