Skip to main content

Fetch POST API, wont send from Front-End to Back-End (beginner)

My GET ist working, bu not my POST. What am I missing?

server:


const data = {"data":["i will do everything for love", "Anything you've been dreaming of"]};

app.get("/", (req, res) => {
  res.json(data);
});
app.post("/", (req, res) => {
  res.json(data);
});

And FrontEnd:


function Test() {
 
  const [testPost, setTestPost] = useState([{ "data": "but I just won't do that" }]);

  const handleClick = () => {
    console.log("i am click");
    fetch("http://localhost:5000/", {
      method: "POST",
      headers: { "Content-Type": "apllication/json" },
      body: JSON.stringify(testPost),
    })
    .catch((err) => {
      console.log("rejected", err);
    })
    .then(
      console.log("i am then")
    )
    };

When i click the botton "post" i get both console.logs, no error. but with refreshing my server, no update is comming :(

Via Active questions tagged javascript - Stack Overflow https://ift.tt/mPxjc1u

Comments