I am working on a serverless application using AWS Lambda, a MYSQL database and API Gateway as Backend. I have several functions already working which use GET or POST methods to query the database. However, now I need to perform a query using data that the user selects in the web app. It is just a simple query, however, I am running with the following problem: when I send the query as a simple string, the API works well, although the query gives error (because I didn't send in the JSON format that Lambda works with). However, when I try to send a JSON object, the API gives the following error: Access to XMLHttpRequest at '...' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
This is my javascript code: `
var queryJSON = '{ "filter": "' + query + '"}';
function get_statistics() {
$.ajax({
url: "url...",
type: "get",
data: queryJSON,
success: function(response) {
console.log(response);
},
error: function(xhr) {
console.log(xhr);
}
});
}`
Probably I am doing some mistake, but I don't manage to figure it out, thanks :)