- We create a new
XMLHttpRequest
object and open a GET request to the JSONPlaceholder API (a fake online REST API). - When the request is successful (status code 200), we parse the JSON data and display it on the page.
The Fetch API is a modern alternative to XMLHttpRequest
. It's easier to use, more flexible, and based on Promises, making it simpler to handle asynchronous requests.