-1

I'm posting form data. I want to not trigger CORS when I send the HTTP request.

I'm using jquery's $.ajax call thus:

    $.ajax({
                            method: "POST,
                            url: url,
                            data: e.serialize(),
                            cache: !1,
                            dataType: "json",
                            contentType: "application/json; charset=utf-8",
                            error: function(e) {
                                alert("Could not connect to the registration server. Please try again later."), console.log(e)
                            },
                            success: function(e) {
                               console.log("success")
                          } 
})

Presently when this is called, my browser returns the message:

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

This seems self-explanatory: 'Access-Control-Allow-Origin' isn't configured as an http header for that resource. CORS is not enabled for the resource.

That's fine. And means I can send the request without bothering about CORS, right? The users browser is trying to protect the user, where no protection is really neccessary.

The thing is, I'm stuck with trying to send the request without triggering CORS. How do I configure my request to prevent CORS from kicking in?

Thanks.

bob
  • 753
  • 4
  • 15
  • 27
  • 2
    Your request has nothing to do with it—rather the server. CORS would be pointless if requests could bypass it without appropriate server configuration. – Dave Newton Jan 22 '20 at 22:53

1 Answers1

2

You completely misunderstand CORS. CORS doesn't block or prevent you from doing anything; rather, using it lets you do things that you otherwise couldn't (because the same-origin policy disallows them). Your error message is telling you that your request was blocked because you weren't using CORS, not because you were. Rather than seeking to disable CORS, you instead need to use it! Modify your second server to send an Access-Control-Allow-Origin header that allows the first one.