Keep an active session with front-end angularjs and php backend [closed]

-1

I am developing a SPA application in angularjs and the backend is done with PHP. The problem is when a user does not use the application for some time and the session expires. At that moment the request is made to the backend and since I am saving some data in the php session, it seems that it is processing eternally.

How do I avoid this?

    
asked by Mario Ramos 14.03.2017 в 02:36
source

1 answer

2

A solution would be to send an ajax to the server renewing the session every so often

UPDATE 1:

Puedes hacer algo como esto en tu .js

$(document).ready(function(){
    setInterval(sessionRenew, X);//Se ejecutara sessionRenew cada X tiempo dado en milisegundos
});
function sessionRenew(){
    $.ajax({
        url: '/path/to/file', // Archivo donde renueva sus datos
        type: 'POST', //Tipo de envio al server
        data: {session: 'renew'}, //Parametros que envias
        success: function(resp){
            doSomething(); //Que hacer despues de una respuesta
            console.log('Session renew' + resp); //Comunicar a la consola JS el msg
        }
    })//Aqui en adelante puedes ver la documentacion de jQuery Ajax, es teoricamente un equivalente a lo anterior
    .done(function() {
        console.log("success");
    })
    .fail(function() {
        console.log("error");
    });
}
    
answered by 14.03.2017 в 03:13