How do I make an HTTP request in Javascript?
To make an HTTP request in JavaScript, you can use the `XMLHttpRequest` object or the newer `fetch` API. Here's an example of how to use both methods: Using XMLHttpRequest: ```javascript var xhr = new XMLHttpRequest(); xhr.open("GET", "https://api.example.com/data", true); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { var response = JSON.parse(xhr.responseText); console.log(response); } }; xhr.send(); ``` Using fetch API: ```javascript fetch("https://api.example.com/data") .then(function(response) { if (response.ok) { return response.json(); } else { throw new Error("Error: " + response.status); } }) .then(function(data) { console.log(data); }) .catch(function(error) { console.log(error); }); ``` Both methods demonstrate making a GET request to ...