How to refresh on another page after entering data in the database

Asked

Viewed 583 times

2

i am creating a service system where there is a screen only to display the passwords that are being registered in the database.

The problem is that I can’t update the passwords in real time, because I’m calling them from another page, I just managed to use schemes to keep updating the page every certain time, I wonder if I can do this asynchronous along with ajax.

This is the code of the screen that calls the passwords

<script>
        $(document).ready(function Att() {
            $.ajax({
                url: '../SenhaController',
                data: 'json',
                success: function (data) {          
                    $.each(data.nomeNormal, function (idx, obj) {
                        $('#tabelaNorm').ready().append("<tr><td>" + obj.nomeNormal + "</td><tr>");
                    });
                    $.each(data.nomePref, function (idx, obj) {
                        $('#tabelaPref').ready().append("<tr><td>" + obj.nomePref + "</td><tr>");
                    });
                }
            });

        });
    </script>

And this is where I register the passwords

<script>
        $(document).ready(function () {

                $('#submit').click(function (event) {

                    var username = $('#name').val();
                    var senha = $("input[name='senha']:checked").val();

                    $.getJSON('../gerarSenha', {user: username, senha: senha}, function (resposta) {

                        $('#resultado').html(resposta.respostaNormal).fadeIn().delay(1000).fadeOut();
                        $('#resultado').html(resposta.respostaPref).fadeIn().delay(1000).fadeOut();
                        $('#name').val('');
                    });
                });
            });
    </script>

Thank you in advance.

  • Sure want to use refresh?

  • http://answall.com/questions/38467/como-consultar-a-db-sem-refresh-e-writingos-relateds?rq=1 - Duplicate?

  • Not necessarily, I just need the password screen data to be updated as soon as I enter a new password into the database, the problem is that the password screen is on another page and I can’t do that, I’ve circled the forum with several similar problems but no equal

  • All right, sorry for the mistake, I think it would be great to use this will help a lot of people, I preferred the question to see the answer later ;)

  • Let me get this straight, one page you enter the password in the database, the other page you search the passwords. But I wanted it to be in "real time"?

  • That’s right lionbtt, I have a page that I register these passwords like a "Triage", the page that displays the passwords they only search via ajax, so I wanted this page to update in real time, if you need to update the page to appear next

  • @Rafaelmonteiro, some frameworks like Meteorjs handle this type of scenario very well, in any case you will need to make a change on the Server side to achieve the expected result. So, what Voce is using on the server side?

  • I will give a research on this Meteorjs, I am working with java treatment by Servlet

Show 3 more comments

1 answer

-1

As in the model client x server you do not maintain a persistent connection to the server, in the case when a request is sent to be processed, to be answered that connection ends and you no longer have the reference of the page that made that request, which would make it impossible to do what you are trying, however, there are some ways to do this:

  1. Refresh the page you want the information from time to time, can also be used ajax to make a GET without refreshing the whole page.

  2. Using Websockets that simulate a "persistent connection" to the server, so when you open the page that you want this information in real time, it would simulate a persistent connection to your server and keep it without losing it (as long as you persist this somewhere, on a static map for example), so when there was an Sert you would trigger an event that would notify that page in question, being able to broadcast for all connections or notification only for a specific page.

  3. According to the documentation of open window., if you run window.open and specify the name of that page, the next time you perform this function the page will be overwritten with the url you will provide, so if you pass it a refresh should work, but this method would only work if you had opened the second page from the first.

Browser other questions tagged

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