From 3ff03208f7b402f14f4e3ef5a192b5a8a7aa0d82 Mon Sep 17 00:00:00 2001 From: Cotton Hou Date: Thu, 27 Jul 2023 05:45:25 +0800 Subject: [PATCH] Simplify Ajax call sample code on Fetch response --- files/en-us/web/api/response/index.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/files/en-us/web/api/response/index.md b/files/en-us/web/api/response/index.md index 03bd899b1b77532..c56be0e323bc218 100644 --- a/files/en-us/web/api/response/index.md +++ b/files/en-us/web/api/response/index.md @@ -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