CORS Demo
Make a request to an API endpoint hosted in AWS API Gateway to test CORS fix
HTML
<div id="banner-message">
<button>Make Request</button>
<p id="response-container">
Response will go here...
</p>
<p>
Tip: If you do not get a response, check the console log in your developer tools
</p>
</div>
JavaScript
// UI
var button = $("button")
var responseContainer = $("#response-container")
var apiUri = "https://189ivt1vog.execute-api.eu-west-1.amazonaws.com/test/mockapi"
// handle click and add class
button.on("click", () => {
$.ajax({
type: "GET",
url: apiUri,
dataType: 'json',
timeout: 5000,
success: function(data) {
var timestamp = Date.now()
responseContainer.html(`<pre>${timestamp}: ${JSON.stringify(data)}</pre>`);
},
error: function(error) {
responseContainer.html(error);
}
});
})