-1

I am using React and node js. The most common solution out there is to add access-control-allow-origin to the code. But I did not understand where and how to put that in my code. Here is my react code for making a post request.

const handleSubmit = (e) => {
    e.preventDefault();
    fetch("http://localhost:8000/login", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify("holla"),
    });
  };

And here is my function for handling post request

router.post("/login", (req, res) => {
  console.log(req.body);
  return res.redirect("back");
});
Aaditya_23
  • 5
  • 1
  • 3
  • There are many many previous questions about this topic: https://stackoverflow.com/search?q=No+%27Access-Control-Allow-Origin%27+CORS+javascript – jcollum Sep 05 '21 at 23:11
  • Please read carefully, I have written none of them works. – Aaditya_23 Sep 05 '21 at 23:28
  • "None of them works" isn't really an acceptable response around here. We need to see what you've actually tried. Also, you didn't say none of them work, you said one thing didn't work. Also, your response came off as kinda snotty. – jcollum Sep 06 '21 at 02:41

1 Answers1

-1

Seems you’re having some cors issue visit Why does my JavaScript code receive a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error, while Postman does not?

You could also visit cors on Mozilla:

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

jireh
  • 1
  • 3
  • No Sir, this was not at all helpful. And I've already seen these links before, this just didn't worked for me. – Aaditya_23 Sep 05 '21 at 23:29