How to make a refresh more dynamic?

1

Is there any method of fetching data from a server by putting it directly to a page without having to use a basic javascript example: ??

setInterval(function() {
    $.ajax({
       type: "POST",
       url: "retorno.php",
       data: 'id=1',
       cache: false,
       success: function(html) {
           $("div").html(html);
       }
   });
}, 1000);

Because with this type of example I can not make it more dynamic with the page. EXAMPLE:

If it is to list a conversation between two people, with this code, I can not release a notification sound to alert the new message user.

There is some way of using this kind of code, so make sure to handle it, because on setInterval the page would be refreshing from time to time, preventing you from parsing the code.

Type the Facebook notification where it appears to be directly on the page and only notifies you when the server has changed.

    
asked by anonymous 31.07.2015 / 18:41

1 answer

0

You can use WebSocket, although indirectly the server procedure is the same, only executed by a thread in the application layer of the software. In the case of WebSocket there is a / Thread service that performs validation of the data and sends a return to the browser, which is waiting for the answer (Listining). An interesting link to analyze some of the alternatives of WebSocket (HTML5).
link

In this URL we find some languages in which we can instantiate our WebSocket server, Java,. Net, NodeJS, among others.

Another interesting reference on WebSocket
link

On the IBM site you have a cool example of chatting with WebSocket

    
05.08.2015 / 02:53