Dynamically consult data

Asked

Viewed 58 times

-1

I have a question: I have a query in the database made in PHP that returns numbers that are updated to each request I make when accessing the browser. When I give F5, the data is updated and see them on the screen, until ai blz. Only I wanted this data to be updated instantly without having to give F5 in the browser and without using the request every few seconds. I wanted to do this using Jquery for example. I already fucked the net here and I can’t find anything, just a lot of codes I don’t understand. rsrs

Thanks in advance.

  • "without using the request every few seconds" <- this is an alternative, the other is websocket. If no one answers I’ll give you an answer later on that.

  • Server-Sent Events is also an alternative

  • I will search both and see if I can use. Thanks for the reply. Sergio and Hwapx.

  • You managed to fix this?

1 answer

0

In jQuery it would be more or less that:

        function refresh() {
            $.ajax({
                url: "url_da_pagina.php"
            }).done(function (msg) {
                alert(msg);
                //aqui vc trata os dados do resultado
            });
        }

        setInterval(function() { refresh(); }, 3000);
  • The author of the question specified that he did not want a solution that made requests every few seconds. I believe this extends to Ajax requests as well.

Browser other questions tagged

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