Skip to content

Commit

Permalink
исправляет вызов метода sendData
Browse files Browse the repository at this point in the history
  • Loading branch information
Suninall committed Dec 30, 2024
1 parent dd01167 commit e4c5d7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions js/form-filling.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
10 changes: 5 additions & 5 deletions js/interact-with-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};

0 comments on commit e4c5d7f

Please sign in to comment.