Skip to content

Instantly share code, notes, and snippets.

@Manyaka
Created January 13, 2021 09:08
Show Gist options
  • Save Manyaka/cc42a13a5a3c21211d4c9e61365883a7 to your computer and use it in GitHub Desktop.
Save Manyaka/cc42a13a5a3c21211d4c9e61365883a7 to your computer and use it in GitHub Desktop.
Ajax Call
// Function to do an Ajax call
const doAjax = async () => {
const response = await fetch('Ajax.php'); // Generate the Response object
if (response.ok) {
const jVal = await response.json(); // Get JSON value from the response body
return Promise.resolve(jVal);
}
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment