Skip to content

Instantly share code, notes, and snippets.

@SuryaSankar
Created February 20, 2020 13:08
Show Gist options
  • Select an option

  • Save SuryaSankar/9b35029d507923a2142a5ec68a024764 to your computer and use it in GitHub Desktop.

Select an option

Save SuryaSankar/9b35029d507923a2142a5ec68a024764 to your computer and use it in GitHub Desktop.
Webpush basic functionality - Admin
<html>
<head>
<link rel="icon" href="data:,">
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
</head>
<body>
<h1>Trigger a Push Notification</h1>
<form method="POST" id="trigger-push-form" action="/admin-api/trigger-push-notifications">
<div>
<label for="title">Message Title: </label>
<input name="title"/>
</div>
<div>
<label for="body">Message Body: </label>
<textarea rows="10" cols="100" name="body"></textarea>
</div>
<input type="submit" value="Trigger Push">
</form>
<script type="text/javascript">
$(function(){
$("#trigger-push-form").submit(function(event){
event.preventDefault();
$.ajax({
type: 'POST',
url: $("#trigger-push-form").attr("action"),
contentType: 'application/json',
processData: false,
data: JSON.stringify(
$("#trigger-push-form")
.serializeArray()
.reduce(function(result, item){
result[item.name] = item.value;
return result;
}, {})
),
success: function(response) {
console.log("received response ", response);
},
});
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment