Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Formatted snippet authored by Jeff Richards (http://www.jrichards.ca/)
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
function submitToAPI() {
var URL =/contact’;
var data = {
name: $(‘#name-input’).val(),
email: $(‘#email-input’).val(),
description: $(‘#description-input’).val()
};
$.ajax({
type:POST’,
url: URL,
dataType: ‘json’,
contentType: ‘application/json’,
data: JSON.stringify(data),
success: function () {
// clear form and show a success message
alert(‘yay’);
},
error: function () {
// show an error message
alert(‘boo’);
}
});
}
</script>
</head>
<body>
<form id="contact-form">
<label for="name-input">Name:</label>
<input type="text" id="name-input" placeholder="name here…" />
<label for="email-input">Email:</label>
<input type="email" id="email-input" placeholder="email here…"/>
<label for="description-input">How can we help you?</label>
<textarea id="description-input" rows="3" placeholder="tell us…"></textarea>
<button type="button" onClick="submitToAPI()">Submit</button>
</form>
</body>
</html>
@dangayle

This comment has been minimized.

Show comment
Hide comment
@dangayle

dangayle May 10, 2017

Smart quotes?

Smart quotes?

@mrpackethead

This comment has been minimized.

Show comment
Hide comment
@mrpackethead

mrpackethead Jun 16, 2018

When i try to use this i get a bunch of CORS related errors it seems; Not sure what i need to do to fix it.

Failed to load https://v3q4sxptdj.execute-api.us-east-1.amazonaws.com/production/submit: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://ariseforms.s3-website-ap-southeast-2.amazonaws.com' is therefore not allowed access
.
Cross-Origin Read Blocking (CORB) blocked cross-origin response https://v3q4sxptdj.execute-api.us-east-1.amazonaws.com/production/submit with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.

When i try to use this i get a bunch of CORS related errors it seems; Not sure what i need to do to fix it.

Failed to load https://v3q4sxptdj.execute-api.us-east-1.amazonaws.com/production/submit: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://ariseforms.s3-website-ap-southeast-2.amazonaws.com' is therefore not allowed access
.
Cross-Origin Read Blocking (CORB) blocked cross-origin response https://v3q4sxptdj.execute-api.us-east-1.amazonaws.com/production/submit with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment