Skip to content

Instantly share code, notes, and snippets.

@fabianofranz
Created May 6, 2014 19:07
Show Gist options
  • Save fabianofranz/34cb348a01cd5566a37f to your computer and use it in GitHub Desktop.
Save fabianofranz/34cb348a01cd5566a37f to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var form = $('#form'); // contact form
// form submit event
form.on('submit', function(e) {
e.preventDefault(); // prevent default form submit
$.ajax({
url: 'http://localhost:8080/forcegym/api/forcegym/plans', // form action url
type: 'POST', // form submit method get/post
dataType: 'json', // request type html/json/xml
data: JSON.stringify({
'plan': {
'active': true,
'description': form.children("description").text(),
'name': form.children("name").text(),
'price': form.children("price").text()
}
}),
beforeSend: function(data) {
},
success: function(data) {
alert('done!');
},
error: function(e) {
alert('error: ' + e);
}
});
});
});
</script>
</head>
<body>
<h1>Contact us</h1>
<form id="form" action="" method="post">
<input type="text" name="description" />
<input type="text" name="name" />
<input type="text" name="price" />
<button>Send Mail</button>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment