1

Does CORS error is related to front end or back end? If it's from front end, how to handle it? I'm getting Error

I got little bit move forward. Now, i'm getting No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access error. How to add header to it?

My Ajax call is:

$.ajax({
                    type: "POST",
                    url: url,
                    //contentType: "application/json; charset=utf-8",
                    crossDomain:true,

                    data: JSON.stringify(feederData),
                    dataType: "json",
                    success: function (data) {
                        console.log(data);
                        if (data === true) {
                            alert();
                        }
                    },
                    error: function (a, b, c) {
                        console.log(a);
                        alert(a);
                    }
                });
Chanikya
  • 476
  • 1
  • 8
  • 22
  • STILL please first google the error message https://www.google.nl/search?q=No+%27Access-Control-Allow-Origin%27+header+is+present+on+the+requested+resource.+Origin+%27null%27+site%3Astackoverflow.com – mplungjan Oct 11 '18 at 11:23
  • https://stackoverflow.com/questions/35304817/basic-ajax-request-gets-no-access-control-allow-origin-header-is-present-on-t – mplungjan Oct 11 '18 at 11:25

2 Answers2

1

The Ajax endpoint not have support for the OPTIONS method enabled.

You need to add support for OPTIONS on the backend and also have CORS on OPTIONS

You have likely added a header on the client that makes the AJAX trigger preflight

Answer to new question

Basic AJAX request gets "No 'Access-Control-Allow-Origin' header is present on the requested resource" error

mplungjan
  • 169,008
  • 28
  • 173
  • 236
-1

That's a backend issue. It's saying that OPTIONS method requests are not allowed on the endpoint. 405 Method Not Allowed.

The CORS headers are in place, but the endpoint needs to allow OPTIONS requests. Preflight requests to get these CORS headers use the OPTIONS method and the server should respond with an empty 200 response that includes the headers.

OK sure
  • 2,617
  • 16
  • 29