Maintain button status even with page refresh?

Asked

Viewed 140 times

0

Look at the gif image!

inserir a descrição da imagem aqui

The button is with the status of Pause Processing, and should only return with the status of Pause Processing only after it is clicked again, what happens is that the status changes when a refresh is done on the page, the expected behavior was that it would maintain the status of Follow Processing even if a refresh was made on the web page, if only change status only after clicking the button, as I do to fix this problem?

This is my button;

<button id="btnAcao" type="button" class="btn btn-primary" title="Pausar Processamento" onclick="pausar();">
    <i class="glyphicon glyphicon-pause"></i> Pausar Processamento
</button> 

This is my javascript file on the page;

function pausar(){
    var $btnAcao = $('#btnAcao');

    alert("status do botão  "  + $btnAcao.text().trim());

    if ($btnAcao.text().trim() === 'Pausar Processamento') {
        //$btnAcao.text('Iniciar Processamento');
        $btnAcao.html('').html("<i class='glyphicon glyphicon-play'></i> Seguir Processamento");
        $btnAcao.attr("title", "Seguir Processamento");
    } else {
        //$btnAcao.text('Pausar Processamento');
        $btnAcao.html('').html("<i class='glyphicon glyphicon-pause'></i> Pausar Processamento");
    $btnAcao.attr("title", "Pausar Processamento");
    }

    $.post('AdministracaoRemessa!pausar', function(retorno) {});
}
  • 2

    You can even do this by locally storing the status of the button, but it would open the door to later problems. The ideal solution is that you check on the server the status of this "processing" and display the button as the result. Basically, if "processing" is active, display the pause button, if it is paused display the following button.

  • there is a javascript method for this? it seems that has the on and the off right?

  • 1

    No, it depends on your backend. You can do this in server-side, when you build the HTML page or need to make the request asynchronously from Javascript.

No answers

Browser other questions tagged

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