Short Notes on JS

From PaskvilWiki
Revision as of 13:21, 24 January 2020 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Fetch Patterns

fetch("url", { options... })
  .then((response) => {
    if (!response.ok)
      throw new Error('Network response was not ok');
    return response.json();  // or response.blob(), etc.
  })
  .then((data) => {
    // do something with the data received
  })
  .catch((error) => {
    console.error('Failed to fetch:', error);
  });