In Javascript, you can make HTTP requests using the XMLHttpRequest
object or by using the fetch
API. Here is an example of making a GET request using XMLHttpRequest
:
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://www.example.com", true);
xhr.send();
xhr.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
console.log(this.responseText);
}
};
And here is an example of making a GET request using fetch
:
fetch("https://www.example.com")
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error(error));