Skip to main content

MAKE HTTP REQUEST IN Java Script | codes

 You can make an HTTP request in JavaScript using the XMLHttpRequest object or the fetch API.

Using XMLHttpRequest:

javascript
const xhr = new XMLHttpRequest(); xhr.open('GET', 'https://example.com/api/data', true); xhr.onload = function() { if (xhr.status === 200) { const response = JSON.parse(xhr.responseText); console.log(response); } }; xhr.onerror = function() { console.error('Request error'); }; xhr.send();

Using fetch:

javascript
fetch('https://example.com/api/data') .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Fetch error:', error));

Both methods allow you to send requests and handle responses, but the fetch API is newer and more streamlined, while XMLHttpRequest is more versatile and supports features like aborting a request.

Comments

Popular posts from this blog

Download Radhe Movie (2021) 480p FilmyZilla Full HD, Tamilrockers

In the wake of taking the feared criminal Gani Bhai, ACP Rajveer Shikawat also known as Radhe goes on a manhunt to track down the most well off man of the town furtively running a criminal organization Radhe is an upcoming Indian Hindi-language action film directed by Prabhu Deva and produced by Salman Khan, Sohail Khan and Atul Agnihotri. A remake of 2017 Korean film The Outlaws, the film stars Salman Khan, Disha Patani, Randeep Hooda and Jackie Shroff. Wikipedia Release date: 13 May 2021 (India) Trending Director: Prabhu Deva Based on: The Outlaws; by Kang Yoon-sung Music director: Himesh Reshammiya, Sajid–Wajid, Sanchit Balhara, Devi Sri Prasad Producers: Salman Khan, Atul Agnihotri, Sohail Khan, Nikhil Namit Watch now Also read :- कोरोना के कारण फंगल संक्रमण How to download  Gta 5  Gta 5 download apk Gta 4 Download for pc नए कोविड स्ट्रेन लक्षण मूल से अलग कैसे हैं Karma Book by Sadhguru वैक्सीन के दोनों डोज लगे हों तो भी कोरोना हो सकता है Coronavirus nibandh in hindi ...

How to remove pimples naturally and permanently in one day at home

 Stains and stubborn pimples that appear on the face, along with spoiling beauty, also work to reduce your confidence.  If you are also troubled by stubborn pimples then leave tension and adopt this effective solution. Let us know what are these remedies. The stains and stubborn pimples that appear on the face, along with spoiling the beauty, also work to reduce your confidence. Pimples can appear on the face anytime between the age of 14 to 30 years. The person has a lot of trouble while the pimples are coming out. Which later appear as white, black and burning red spots on the face. If you are also troubled by stubborn pimples then leave tension and adopt this effective solution. Let's know what are these solutions.  Why do pimples come out?  Acne begins to appear on the face when oil and deadskin are gathered in the pores of the skin. In fact, when the secretion from fat glands (sibbius glands) sto...