Created
January 13, 2021 09:08
-
-
Save Manyaka/cc42a13a5a3c21211d4c9e61365883a7 to your computer and use it in GitHub Desktop.
Ajax Call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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