Message from JavaScript discussions

February 2017

— +1

— 

Tiny baby ajax

function ajax (url = "/", resType = 'text') {
return new Promise (function (resolve, reject) {
var req = new XMLHttpRequest();
req.onreadystatechange = function () {
if (req.readyState === 4) {
if (req.status >= 400 && req.status < 600) {
reject("HTTP Error " + req.status + ": " + req.statusText);
} else if (req.status >= 200 && req.status < 400) {
resolve(req.response);
}
}
};
req.open("GET", url);
req.responseType = resType;
req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
req.send();
});
}

— 

ajax("/url", "json").then(function (response) {

  console.log(response.prop);

});

— +1. But this condition && req.status < 600, is really necesary?

— Just seem too paranoid, but I think it's ok 😂

— Heh

— Designers Hub - UI/UX
Community to share queries, post tips, latest trends and tricks relating to UI/UX design development. Articles from across groups into one repository... Lets Go Design how2design
https://t.me/how2design

Message permanent page

— Other Admins, DO NOT delete this! Yes it is spam (because no one requested and is almost not related to js) but Fazal is the admin of this group. So let's allow this post this time.

Message permanent page

— Right

— My apologies. I had sent request to few admins who were common admins for multiple groups. Seems this group is not owned by them. Thank you for allowing it for the timebeing.

Message permanent page

— Other programming group admins think too high of themselves as if they are Mark Zuckerberg or Larry Page. Admins of this group seem cooler though like a JS Dev should be.

Message permanent page

— It's easier to be a "cool" admin in a small 100 person group with well-behaved people :)