From e4c5d7f640ea45c74eb5f493b06e8591017b39b7 Mon Sep 17 00:00:00 2001 From: Suninall Date: Mon, 30 Dec 2024 23:13:21 +0700 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20sendData?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/form-filling.js | 3 +-- js/interact-with-data.js | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/js/form-filling.js b/js/form-filling.js index e699da6..4667714 100644 --- a/js/form-filling.js +++ b/js/form-filling.js @@ -24,9 +24,8 @@ imgInput.addEventListener("change", (evt) => { evt.preventDefault(); formButton.disabled = true; if(pristine.validate()){ - openSuccess(); const formData = new FormData(evt.target); - sendData(showAlert,formData); + sendData(showAlert,formData,openSuccess)(); }else { openError(); } diff --git a/js/interact-with-data.js b/js/interact-with-data.js index 0308aa8..8ed45f4 100644 --- a/js/interact-with-data.js +++ b/js/interact-with-data.js @@ -21,21 +21,21 @@ const getData = (onSuccess, onError) => () => onError("Не удалось загрузить данные. Попробуйте ещё раз"); }); -const sendData = (onError,formData) => () => +const sendData = (onError,body,onSuccess) => () => fetch ( "https://29.javascript.htmlacademy.pro/kekstagram", { method: "POST", - credentials: "same-origin", - body: formData, + body, }, ) .then((response) => { if (!response.ok) { - throw new Error(); + throw new Error("Не удалось отправить форму. Попробуйте ещё раз"); } + onSuccess(); }) .catch(() => { - onError("Не удалось отправить данные. Попробуйте ещё раз"); + onError("Не удалось отправить форму. Попробуйте ещё раз"); }); export{getData,sendData};