=================================================================== RCS file: /cvs/cvs/draft/form.min.js,v retrieving revision 1.43 retrieving revision 1.54 diff -u -p -r1.43 -r1.54 --- draft/form.min.js 2024/03/29 18:42:52 1.43 +++ draft/form.min.js 2024/03/29 20:59:52 1.54 @@ -51,21 +51,39 @@ async function sendData() { // feed=JSON.stringify(ob); //$.post("/feedbk/", feed, function(data, status){ // console.log("Data: " + data + "\nStatus: " + status); +// console.log(data); +// console.log("JSON: " + JSON.parse(data) ); +// //}); /* --------------------- */ -//var re=""; -re=fetch('/feedbk/', { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ "cfem": "a@b.ru", "cfsu" : "subject", "cfme" : "message", "cfto" : "token" }) -}); - .then(response => response.json()) - .then(response => console.log(JSON.stringify(response))) -// console.log(re); - +//ovar re=""; +const dataToSend = JSON.stringify({"email": "hey@mail.com", "password": "101010"}); +let dataReceived = ""; +fetch("/feedbk/", { + credentials: "same-origin", + mode: "same-origin", + method: "post", + headers: { "Content-Type": "application/json" }, + body: dataToSend +}) + .then(resp => { + if (resp.status === 200) { + return resp.json() + } else { + console.log("Status: " + resp.status) + return Promise.reject("server") + } + }) + .then(dataJson => { + console.log(dataJson); + dataReceived = JSON.parse(dataJson) + }) + .catch(err => { + if (err === "server") return + console.log(err) + }) +console.log(`Received: ${dataReceived}`) + }, });