JSFiddle - React, Tailwind, and code Playground

by jwerre

HTML

<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<h1>Simple CORS request</h1>
<button id="trigger">trigger</button>

JavaScript

var API_URI = "https://gsjvt40jec.execute-api.us-west-2.amazonaws.com/v1/contact"

$('button#trigger').click(function(e) {
    e.preventDefault()
    $.ajax({
        url: API_URI,
        type: "POST",
        crossDomain: true,
        cache: false,
        contentType: 'application/json',
        data: JSON.stringify({
		  "name": "Jonah Werre",
		  "email": "[email protected]",
		  "subject": "API Ajax Test",
		  "message":"This is a Lambda test from the AWS API Gateway"
		}),
        success: function(response) {
            var resp = JSON.parse(response)
            console.log(resp.status);
        },
        error: function(xhr, status) {
            console.error("Error:", status);
        }
    });
});