Refresh page information without refreesh

Asked

Viewed 95 times

5

I’ve looked and I haven’t found exactly what I want.

My problem is this: I have a comments page that I wanted to update every change in the bank (this for everyone who is connected at that time).

I found some methods on the web that used setTimeOut() to keep updating, but not really liked 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 cited earlier (with Javascript updates)

How can I do this?

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, worth reading everything, has how to use too.

Browser other questions tagged

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