How do I make an HTTP request in Javascript?

  1. Using the XMLHttpRequest object:
Copy codevar xhr = new XMLHttpRequest();
xhr.open("GET", "https://example.com", true);
xhr.onload = function () {
    console.log(xhr.responseText);
};
xhr.send();