Skip to content

Instantly share code, notes, and snippets.

@pradeep1991singh
Created August 3, 2018 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pradeep1991singh/ba344b765aee7c08821ff51ce7258607 to your computer and use it in GitHub Desktop.
Save pradeep1991singh/ba344b765aee7c08821ff51ce7258607 to your computer and use it in GitHub Desktop.
Beacon api
// URL to send the data to
let url = '/api/my-endpoint';
// Create a new FormData and add a key/value pair
let data = new FormData();
data.append('hello', 'world');
let result = navigator.sendBeacon(url, data);
if (result) {
console.log('Successfully queued!');
} else {
console.log('Failure.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment