4

I am using navigator.sendBeacon() api, I understand its benefits of sending data even onunload, but why should we use it when it only returns a value of whether the data is being queued or not and does not help us in checking if the data is sent to the server side successfully. Could someone help me in understanding this and provide a solution to check if the data has been sent to the server successfully.

astudent
  • 67
  • 1
  • 7

1 Answers1

4

The point of sendBeacon is to send data when you can't wait for a response anyway (such as when the browser is leaving your site and you want to send analytics data to your database).

There isn't a way to get a success or fail state from it, because it is designed for situations where your JS program is exiting (and can't block the exit).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335