Created
October 29, 2019 22:14
-
-
Save peterbsmyth/81bb33c85cf895ae4cd526b1bb67b556 to your computer and use it in GitHub Desktop.
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
function reqListener() { | |
var data = JSON.parse(this.responseText); | |
console.log(data); | |
} | |
function reqError(err) { | |
console.log('Fetch Error :-S', err); | |
} | |
var request = new XMLHttpRequest(); | |
request.onload = function() { | |
var data = JSON.parse(this.responseText); | |
//do stuff with data | |
}; | |
request.onerror = function() { | |
alert('There was a problem with the request'); | |
} | |
request.open('get', '/api/foo/bar', true); | |
request.send(); |
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
fetch('/api/foo/bar').then(function(data) { | |
return data.json(); | |
}).then(function(jsonData) { | |
//do stuff with the data | |
}).catch(function(e) { | |
alert('There was a problem with the request'); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment