Refresh page information without refreesh

5

I have already searched and did not find exactly what I want.

My problem is this: I have a comment page that I wanted it to be updated with every change in the bank (this is for everyone who is currently logged in).

I found some methods on the WEB that used setTimeOut() to stay updated, but I did not really like the result ....

My AJAX to list is like this:

$(document).ready(function(){
        $('#tabela').empty(); 
        $.ajax({
            type:'POST',
            dataType: 'json',
            url: 'system/getMessages.php',
            success: function(dados){
                for(var i=0;dados.length>i;i++){
                    $('#tabela').append('<tr><td><span>'+dados[i].username+'</span><br />'+dados[i].mensagem+'</td></tr>');
                }
            }
        });
    });

Before this same code was in a function that was using the method I quoted earlier (with JavaScript updates)

How can I do this?

    
asked by anonymous 22.12.2015 / 01:59

1 answer

2

You can use WebSocket in HTML 5.

Introducing WebSocket

The WebSocket specification defines an API that establishes "socket" connections between a web browser and a server. In other words, there is a persistent connection between the client and the server, and both parties can start sending data at any time.

Here has the full text on WebSocket, everything is worth reading, you can also use .

    
22.12.2015 / 02:04