You are on page 1of 1

You can make an HTTP request in JavaScript by using the built-in XMLHttpRequest

object or the newer fetch API.

Here's an example of how to make an HTTP GET request using XMLHttpRequest:

javascript

const xhr = new XMLHttpRequest();


xhr.open('GET', 'https://example.com/api/data');
xhr.onload = () => {
if (xhr.status === 200) {
console.log(xhr.response);
} else {
console.error('Request failed. Status code:', xhr.status);
}
};
xhr.send();

You might also like