Fetching a JSON file using Ajax| Fetch API

The better alternative that makes it simple to fetch JSON files is Fetch, which is a promise-based API in contrast to the callback-based XMLHttpRequest.

A basic fetch request look like this:

async function logJSONData() {
  const response = await fetch("http://example.com/movies.json");
  const jsonData = await response.json();
  console.log(jsonData);
}

Fetching a JSON file using Ajax| Fetch API-codepen

Reference-complete fetch API

1 Like