1
Is there a method of fetching data from a server by directly putting it 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 that kind of example I can’t make it more dynamic with the page. EXAMPLE:
If it’s to list a conversation between two people, with this code, I can’t release a notification sound to alert the new message user.
Is there any way to use this type of code to make it to handle it, because in setInterval
the page would be giving refresh time to time preventing code analysis.
Type the Facebook notification where it appears to be directly on the page and only notifies when there is change on the server.
You can take a look at websocket, it might solve your problem. It’s better than connecting with the server every X seconds. Imagine if a waiter keeps asking every minute if the dish is ready. Terrible! The Boss is the one who notifies the waiter, This is the ideal model. Similarly your browser is ordering from the server every X seconds is very bad. Let the server notify a specific client of any changes. Use technique [Comet][1] [1]: https://pt.wikipedia.org/wiki/Comet_(program%C3%A7%C3%A3o)
– user6406