A
A
Andrei1penguin12021-06-15 01:14:03
JavaScript
Andrei1penguin1, 2021-06-15 01:14:03

Will the data be sent when the offline event is triggered to the server?

Good day, there is a task to send a notification to the server after the user logs out of the network.
Suppose an event hangs on the user side:

window.addEventListener("offline", function() {
    //some ajax request
});

As I understand it, the event is triggered when the user's Internet is disconnected, but how in this case will the request reach the server if the Internet is already disconnected?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Yarkov, 2021-06-15
@Andrei1penguin1

No way. Listen to the event online and send it there.

A
Aetae, 2021-06-15
@Aetae

This task is solved by maintaining a connection with the client and constant ping, for example, via a websocket. If the user is already offline, obviously nothing will go anywhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question