Skip to content

Commit

Permalink
Simplify Ajax call sample code on Fetch response (#28202)
Browse files Browse the repository at this point in the history
  • Loading branch information
imcotton authored Jul 26, 2023
1 parent 6eb518a commit d7951dc
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions files/en-us/web/api/response/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ Here we call a PHP program file that generates a JSON string, displaying the res
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");
return response.json(); // Get JSON value from the response body
}
throw new Error("*** PHP file not found");
};

// Call the function and output value or error message to console
Expand Down

0 comments on commit d7951dc

Please sign in to comment.