P
P
partyzanx2020-05-02 05:07:01
JavaScript
partyzanx, 2020-05-02 05:07:01

Why doesn't unload work?

I'm trying to close the session before exiting the tab with this code

window.unload = function() {
    let xhr = new XMLHttpRequest();
    xhr.open('GET', '/user/sessionDestroy');
    xhr.send();
    };


node.js in router /user/
router.get('/sessionDestroy', (req, res) => {
    console.log(1);
    req.session.destroy();
    res.status(200).send('ok');
})

The code does not work at all, although if you go to the localhost:3000/user/sessionDestroy site, the session is deleted.
Those. back is not receiving a signal at all

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
A person from Kazakhstan, 2020-05-02
@partyzanx

window.onunload - maybe so?

V
Vladimir, 2020-05-02
@HistoryART

/sessionDestroy !== /user/sessionDestroy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question