Created
January 8, 2020 10:09
-
-
Save debuging-life/ab5feb75264853e897aa59cdda1c9b66 to your computer and use it in GitHub Desktop.
PWA
This file contains hidden or 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
| var deferrdPrompt; | |
| if ("serviceWorker" in navigator) { | |
| navigator.serviceWorker | |
| .register("/sw.js") | |
| .then(function() { | |
| console.log("service worker register"); | |
| }) | |
| .catch(function(error) { | |
| console.log(error); | |
| }); | |
| } | |
| window.addEventListener("beforeinstallprompt", function(event) { | |
| console.log("fired"); | |
| event.preventDefault(); | |
| deferrdPrompt = event; | |
| return false; | |
| }); | |
| var promise = new Promise(function(resolve, reject) { | |
| setTimeout(function() { | |
| reject({ code: 500, message: "An error occurred" }); | |
| // resolve("this is executed once the timer is done"); | |
| }, 3000); | |
| }); | |
| var xhr = new XMLHttpRequest(); | |
| xhr.open('GET', 'https://httpbin.org/ip'); | |
| xhr.onload = function() { | |
| console.log(xhr.response); | |
| } | |
| xhr.onerror = function { | |
| console.log('Error!'); | |
| } | |
| xhr.send(); | |
| fetch("https://httpbin.org/ip") | |
| .then(function(response) { | |
| return response.json(); | |
| }) | |
| .then(function(data) { | |
| console.log(data); | |
| }) | |
| .catch(function(error) { | |
| console.log(error); | |
| }); | |
| fetch("https://httpbin.org/post", { | |
| method: "POST", | |
| headers: { | |
| "Content-Type": "application/json" | |
| }, | |
| mode: "cors", | |
| body: JSON.stringify({ message: "Doest this work?" }) | |
| }) | |
| .then(function(response) { | |
| return response.json(); | |
| }) | |
| .then(function(data) { | |
| console.log(data); | |
| }) | |
| .catch(function(error) { | |
| console.log(error); | |
| }); | |
| promise | |
| .then(function(value) { | |
| return value; | |
| }) | |
| .then(resp => { | |
| console.log(resp); | |
| }) | |
| .catch(function(e) { | |
| console.log(e); | |
| }); | |
| console.log("this excute right after settime out"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment