Situatie
Solutie
To make an HTTP request in JavaScript, you can use the built-in XMLHttpRequest
object or the newer fetch()
API.
Here’s an example using XMLHttpRequest
:
To make an HTTP request in JavaScript, you can use the built-in XMLHttpRequest object or the newer fetch() API.
Here’s an example using XMLHttpRequest:
const xhr = new XMLHttpRequest();
xhr.open(‘GET’, ‘https://example.com/api/data’);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText); // the response data
} else {
console.error(‘Request failed’);
}
}
};
Leave A Comment?