Cancel or repeat alert in js

Asked

Viewed 51 times

0

I have the following js to display an alert.

function session_checking1()
{
    $.post( "./alertaposicionamento2", function( data ) {
        if(data.status  == "-1")
        {
           alert('Tem posicionamento em atraso do Utente '+data.value);

        }
    });
}
var validateSession1 = setInterval(session_checking1, 120000);

I wanted that when I displayed the alert to the user, the same user had the option to receive the same alert again or cancel the same alert, and if I canceled the alert activate again after 30 minutes.

Can help?

  • You can work with Sessions and Cookies!

  • @Can Jonathan de Toni explain this process better to better understand? If possible put an example in order to understand this logic?

1 answer

1


I believe changing the alert for confirm and setInterval for setTimeout, as code below solve your problem.

function session_checking1()
{
    $.post( "./alertaposicionamento2", function( data ) {
        if (data.status == "-1")
        {
           if (confirm('Tem posicionamento em atraso do Utente ' + data.value + ', deseja continuar recebendo alerta?')) {
               setTimeout(session_checking1, 120000);
           } else {
               // disparar requisição ajax que faz (data.status == "-1") retornar false 
               // nas próximas requisições, caso a página seja recarregada
           }
        }
    });
}

setTimeout(session_checking1, 120000);
  • Yes, that’s what I want. I just wanted one more thing, and that’s, I don’t want to get this alert anymore, it comes back on after half an hour. So if the user does not comply with what the alert sent, recall it, but thus give a period of time for the user to resolve the request.

  • @Junior it seems your case is only to set a larger timeout on confirm Else.

  • that’s right. Thank you

Browser other questions tagged

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