0

I am trying to make a call to my aws controlled (api-gateway) api.

$.ajax({
       Type: "POST",
       url: "<myURL>",
       crossDomain: true,
       data: <payload>,
       contentType: "application/json",
       success: function(data, status) {
           data = JSON.stringify(data);
           console.log(data);
           if (status == "success") { <action> etc. }

API-Gateway is CORS enabled and has option & post integration response set up:

X-Requested-With    '*' 
Access-Control-Allow-Headers    'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'  
Access-Control-Allow-Origin '*' 
Access-Control-Allow-Methods    'POST,GET,OPTIONS'

I am sending from a S3 hosted static website and have the correct content-type. The same post works with postman as well as gets work. Why does the above one return the below?

OPTIONS 400:

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

Nico Müller
  • 1,784
  • 1
  • 17
  • 37
  • 1
    Is the API-Gateway calling a Lambda function? – jordanw Aug 31 '18 at 16:10
  • yes it is, I didn't implement anything special on the lambda side though, is that it? – Nico Müller Aug 31 '18 at 16:32
  • Check this question/answer. https://stackoverflow.com/questions/40832288/aws-api-gateway-no-access-control-allow-origin-header-is-present/40838956#40838956. Looks like something to do with the GET/POST requests to the Lambda function. – jordanw Aug 31 '18 at 17:31
  • To clarify: i use a mock for the options call awith the integration and response details above, so I do not see how this can be a lambda issue? – Nico Müller Aug 31 '18 at 20:49

0 Answers0