Created
August 3, 2018 06:32
-
-
Save pradeep1991singh/ba344b765aee7c08821ff51ce7258607 to your computer and use it in GitHub Desktop.
Beacon api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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