0

So ORIGINALLY I think it worked and I don't think I modified it. By it I mean a JS script that posts data to an external site. Now in my console it shows "[01/Jun/2021 20:31:17] "POST /newCheckout HTTP/1.1" 405 -" error

Code is:

let data = {"checkout_id": document.documentElement.innerHTML};

      fetch("https://botach-test-branch.ngrok.io/newCheckout", {
        method: "POST", 
        body: JSON.stringify(data)
      }).then(res => {
        console.log("Request complete! response:", res);
      });
Oze
  • 61
  • 8
  • So what is it that you want to know? The reason why its throwing an error? – JΛYDΞV Jun 02 '21 at 03:38
  • 2
    405 means action not allowed, so it's either the POST request or the OPTIONS preflight req. No way to diagnose much else with the information provided. It's not clear what kind of help is expected. – Dave Newton Jun 02 '21 at 03:39
  • If you're trying to post JSON, you're missing `headers: { "Content-type": "application/json" }` – Phil Jun 02 '21 at 04:39
  • @Phil where would I add that? Thanks btw! – Oze Jun 02 '21 at 04:43
  • @Oze see [Fetch: POST JSON data](https://stackoverflow.com/questions/29775797/fetch-post-json-data) – Phil Jun 02 '21 at 04:44

1 Answers1

-1

From what I understand, somewhere in your code, you are doing

headers.append("Access-Control-Allow-Origin","true")

This will require the server to support OPTIONS method and will throw a 405 if it doesn't.

Rakesh Gupta
  • 3,507
  • 3
  • 18
  • 24