Getting CORS error when calling AWS API from Jquery.
CORS has enabled in API side and I can call using react > Axios but we have to use Jquery for this application.
using this code:
$.ajax({
type: 'POST',
url: "https://awsapiurlhere",
crossDomain: true,
async:true,
data: {
aaa: "444",
bbb: "aaa",
ccc: "ccc"
},
dataType: 'JSON',
cors: true ,
contentType:'application/json',
headers: {
"Access-Control-Allow-Origin":"*",
},
success: function(response, status, xhr) {
if (response) {
console.log("The username you typed has been used!", status);
} else {
console.log("No responce" , status);
}
},
error: function(xhr, status, error) {
console.log("Something went wrong!", status );
}
});
getting
Access to XMLHttpRequest at 'https://url' from origin 'https://cdpn.io' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.