I've created a function that seems to work well in Chrome and Firefox, but it's not functioning properly in IE Edge or IE 11:
async function getJSONDataWithHeaders(url, methodType, responseType) {
return new Promise(async function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open(methodType, url, true);
xhr.responseType = responseType;
setHeaders(xhr);
xhr.onload = await function () {
if (xhr.status == 200) {
resolve(this.response);
}
}
xhr.send();
}).catch(function (err) {
console.log(err);
});
}
This is how I am calling the function:
getJSONDataWithHeaders("https://jsonplaceholder.typicode.com/posts", "GET", "json").then(function (result) {
console.log(result);
});