Response - An Ajax Call

PHOTO EMBED

Sat Mar 05 2022 04:29:28 GMT+0000 (UTC)

Saved by @mboljar

// Function to do an Ajax call
const doAjax = async () => {
  const response = await fetch('Ajax.php'); // Generate the Response object
  if (response.ok) {
    const jsonValue = await response.json(); // Get JSON value from the response body
    return Promise.resolve(jsonValue);
  } else {
    return Promise.reject('*** PHP file not found');
  }
}

// Call the function and output value or error message to console
doAjax().then(console.log).catch(console.log);
content_copyCOPY

https://developer.mozilla.org/en-US/docs/Web/API/Response