I cannot get past cors issue

My code is very simple but still cannot get past cors issue. Please help

I have put contentType: “application/json” in my ajax request. Allow put headers in lambda function file. set cors to true in yml but still no luck

What does your AJAX call look like?

1 Like

Setting cors only enables the HTTP OPTIONS. You also need to make sure you’re setting the Access-Control-Allow-Origin header in the response from your Lambda. You may need to set additional headers like Access-Control-Allow-Credentials too.

1 Like

.ajax({ url: awsEndPoint, contentType: 'application/x-www-form-urlencoded; charset=UTF-8', method : 'POST', data : formData, crossDomain : true, dataType: 'html' }) .done(function(data) { (’#thank-you-form’).modal(‘toggle’);
console.log(data);
});

This how my Ajax looks which works. And my y ml looks like yours…you positive it’s a cors issue vs a 500 error being returned by the lambda expression?

2 Likes

My issue has been resolved. I put this code in my handler.js and function.js

const response = {
statusCode: 200,
headers: {
“Access-Control-Allow-Origin” : “*”,
‘Content-Type’: ‘application/json’// Required for CORS support to work
},
body: JSON.stringify({ “message”: event.body.text })
};

callback(null, response);
1 Like