Problem updating content with ajax?

Asked

Viewed 36 times

1

I’m trying to keep my page always updated with ajax , but as I’m beginner I created some functions that worked , but requires a lot of server process.

LIKE I DID?

1º I created a function that calls a page off (busca_p.php) who has an appointment at the bank and a while

//Função que chama a pagina de consulta 

<script type="application/javascript">
function busca (){
        var numero1 = $("#n1").val();
        var numero2 = $("#n2").val();
        $.post("busca_p.php", {n1:numero1, n2:numero2}, function(retorno){
            $(".msg_porto").html(retorno);
            });

        };

</script>

2nd I used the function setInterval to call the function every 1 second.

<script>
window.setInterval(busca,500);
</script>

// Pagina que consulta e carrega em uma tabela
<table width="95%" border="0" align="left" cellpadding="0" cellspacing="0">
 <tr><td>
 </td></tr>
 <?php
include('conexao.php');
$sql=mysql_query("select * FROM porto ORDER BY id ASC ");
while($dados=mysql_fetch_array($sql)){ 
     $filial = $dados['m'];

?>


  <tr>
    <th width="50%" scope="row">
    <br>

 <?php if($dados['m'] != ''){

     ?>   
<table width="85%" border="0" align="left" cellspacing="0" cellpadding="0">
<tr class="info">
<th scope="row" bgcolor="#DEEBEB">
<div class="fm">
<label> <h6><?php echo $dados['n'].' diz em '.$dados['d']; ?></h6> 
<span style="color: #FF0000"><?php echo wordwrap($dados['m'], 45, "<br />\n"); ?></span></label>
</div>
</th>
</tr>  
</table> 
<br>

<?php }?>

<br>
<?php if($dados['mm'] != ''){?>
<table width="85%" border="0" align="right" cellspacing="0" cellpadding="0">
<tr class="success">
<th scope="row" bgcolor="#C5C5C5"> 
<div class="mm">
<label><h6><?php echo $dados['nm'].' diz em '.$dados['dm'] ?></h6>
 <span style="color: #000000"><?php echo wordwrap($dados['mm'], 45, "<br />\n"); ?></span> </label>  
 </div>
</th>
</tr>
</table>
<br>

<?php }?> 

    </th>   
    </td>
    </tr>


    <?php }?>
    <tr><td>&nbsp;</td></tr>

3º the function calling the query page returns the result and loads in a div.

<div class="msg_porto">...</div>

The problem is that it keeps calling the page of query every 1 second and giving a while in the server and generating a high consumption of processing in the server.

how should I do ?

  • Is it necessary to load every half second? how many records is there in your port table? it is necessary to bring all?

No answers

Browser other questions tagged

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