Push Messages #2

This commit is contained in:
JonatanRek
2019-10-08 16:49:08 +02:00
parent 1f456aaaac
commit e5f1fc61d6
6 changed files with 168 additions and 66 deletions

View File

@@ -25,12 +25,31 @@ if ('serviceWorker' in navigator) {
})
.then(function(token) {
console.log("token is : " + token);
$.ajax({
url: 'ajax',
type: 'POST',
data: {
"token": token
},
success: function(data){
console.log('saved', data);
},
error: function (request, status, error) {
console.log("ERROR ", request, error);
}
});
})
.catch(function (err) {
console.log("Unable to get permission to notify.", err);
});
messaging.onMessage(function(payload) {
console.log("Message received. ", payload);
var notification = new Notification('hello', {
body: "Hey there!",
});
notification.onclick = function () {
window.open("http://google.com");
};
});
})
.catch(err => {