xxxxxxxxxx
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://example.com/api/endpoint", true);
xhr.onload = function () {
if (xhr.status === 200) {
// Success: the request was successful
const data = JSON.parse(xhr.responseText);
console.log(data);
} else {
// Error: the request was unsuccessful
console.error("Error: " + xhr.statusText);
}
};
xhr.send();