You can use the XMLHttpRequest object to make HTTP requests. Here is an example of how to use it to make a GET request to a specified URL:
var xhr = new XMLHttpRequest(); xhr.open('GET', 'https://example.com', true); xhr.onload = function () { // process the response }; xhr.send();
Alternatively, you can use the fetch API which is more modern and easier to use. Here is an example of how to use it to make a GET request to a specified URL:
fetch('https://example.com') .then(function(response) { // process the response });
You can also use the axios library, which is a popular library for making HTTP requests in JavaScript. Here is an example of how to use it to make a GET request to a specified URL:
axios.get('https://example.com') .then(function (response) { // handle success console.log(response); }) .catch(function (error) { // handle error console.log(error); });
Please note that the above examples are for GET request, for other requests like POST, PUT, DELETE etc, you will need to change the method and may need to pass additional parameters.
I write for and assist as the editor-in-chief for 601MEDIA Solutions. I’m a digital entrepreneur since 1992. Articles may include AI assisted research. Always Keep Learning! Notice: All content is published for educational and entertainment purposes only. NOT LIFE, HEALTH, SURVIVAL, FINANCIAL, BUSINESS, LEGAL OR ANY OTHER ADVICE. Learn more about Mark Mayo