3
I’m trying to create a page that is always updated, without having to give refresh.
I created a Javascript function that looks for a select
and while
from another page, but this is generating high consumption in the CPU and the server guys already complained. How do I give forever select
in Javascript without having this problem?
<!---- função que chama a pagina onde tem o while ----->
<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>
<script>
window.setInterval(busca,1000);// coloquei este para ativar a funlção a cada 1 segundo
</script>
Call the page busca_p.php
who has a select
and while
and carries within the div (msg_porto)
.
Works well, but is processing all the time and have complained of high CPU use by the server.
People maybe messed up a little what I tried to pass, but what I try to do is to have my page updated always without having to update the page, so I made a function that calls a page where this consulting the bank and giving a while . So bring the result and click on div (msg_port). And even works but consumes a lot of server cpu because I put the function window.setInterval(search,1000); to call the function that requests the page query every 1 second.
– Cesar Lima Paulo
Javascript does the function of prompting the server for the information that will be returned by PHP without having to refresh the full page. Check this link http://www.mauricioprogramador.com.br/posts/actualizr-parte-do-site-sem-refresh-na-pagina-inteira-com-javascript I hope I helped you.
– Dario Andrade
Dario helped me yes , knowledge is always welcome, but I need my page to update without the need of the user action, and I achieved this only using the function window.setInterval(search,1000) but this makes the server process a lot , I thought if I could have this without having to access a page off , but I might be talking nonsense, but thanks for trying to help me
– Cesar Lima Paulo
What code are you running on the server? Can you put it here? and what HTML is returning? Without that information we can’t help much more.
– Sergio
<div class="msg_port">...</div> //A div that returns with the result
– Cesar Lima Paulo
Using the angular framework, it may solve your problem, since it is dynamic. I don’t know how to use it, but who knows it can even guide you better.
– André Nascimento
Use Web Socket for this, apparently what you want is to have a real-time in your application and Web Socket helps to solve precisely this problem and with a much lower CPU consumption, follows a good introduction: http://www.html5rocks.com/pt/tutorials/websockets/basics/
– Leonardo Villela
@Andrénascimento, I believe that Angular alone does not solve his problem, after all he will still need to consult the server to update the model. on the other hand, there may be something in PHP that does what Meteorjs does, a Model bind connecting the client to the server.
– Tobias Mesquita
@Cesarlimapaulo, The new content is created by your application? I mean, another user accesses another page of the system to insert the new data? if yes, you can use Web Sockets to notify all customers who need this new information.
– Tobias Mesquita