How To Make an HTTP request in Javascript

There are several ways to make an HTTP request in JavaScript, but two of the most commonly used methods are the XMLHttpRequest object and the fetch() function.

#1. Using XMLHttpRequest object:

var xhr = new XMLHttpRequest();'GET', '', true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {

#2. Using fetch() function:

.then(function(response) {
return response.text();
.then(function(text) {

Both examples above make a GET request to and log the response to the console. Keep in mind that fetch is not supported by older browsers.

READ ALSO: How to redirect HTTP to HTTPS | Force HTTPS Using htaccess

Remember to Share this Article with your friends on social media!! Doing this helps us improve and grow our channel and also enables us to help more people online. 
Thank You For Sharing!!!
Looks like you have blocked notifications!

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like