0

I know this has been asked before - hear me out, because this is not working for me. This is my AJAX function:

        $.ajax({
            method: 'POST',
            url: "https://somedomain.org",
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            crossDomain: true,
            headers: {
                "Access-Control-Allow-Origin": "http://www.example.org",
                "Access-Control-Allow-Headers": "X-Foo",
                "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS"
            },
            data: JSON.stringify(generateCartParams()),
            context: document.body,
            success: function (response) {
                console.log(response);
            }
        });

However, this is still getting me an error:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Am I not configuring the settings right?

Edit: I am, of course, setting url and Access-Control-Allow-Origin to the correct addresses - these are just placeholders for this question.

John Lexus
  • 3,576
  • 3
  • 15
  • 33
  • 2
    The `Access-Control-Allow-Origin` needs to be set on the _server_ you're trying to hit, not from the browser. – puddi Oct 18 '18 at 20:34
  • you've put **response** headers in the **request** - you haven't "fixed CORS". CORS is configured on the **server** – Jaromanda X Oct 18 '18 at 20:36
  • Possible duplicate of [How does Access-Control-Allow-Origin header work?](https://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work) – Ivar Oct 18 '18 at 20:37

0 Answers0