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

2

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

The problem is that I can not update the passwords in real time, because I'm calling them from another page, I just managed to get the updates updated every time, I'd like to know if I can do this asynchronously together with ajax.

This is screen code that calls 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 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.

    
asked by anonymous 03.05.2016 / 16:35

1 answer

-1

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

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

  • Use WebSockets that simulate a "persistent connection" with the server, so when you open the page 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 it somewhere, on a static map for example), so when there was an insert you would trigger an event that would notify that page in question, being able to broadcast all connections or notification only to a specific page. / p>

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

  • 03.05.2016 / 18:30