Suppose I have some code like this:-
const Ω = {};
Ω.getJSON = function(url, callback){
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.onload = function() {
if (this.status >= 200 && this.status < 400) {
var data = JSON.parse(this.response);
callback(data);
} else {
console.log(this.status);
}
};
request.onerror = function() {
throw'An Unknown Error';
};
request.send();
}
I want to define a .fail()
function similar to jQuery's $.getJSON one but I have no idea how to do like this.
How can I make a .fail()
function for Ω.getJSON?
Answers and comments appreciated.