Skip to content

Instantly share code, notes, and snippets.

@rturowicz
Last active December 15, 2015 07:59
Show Gist options
  • Save rturowicz/5227770 to your computer and use it in GitHub Desktop.
Save rturowicz/5227770 to your computer and use it in GitHub Desktop.
JQuery forms
// basic
$(document).ready(function() {
$('#contact').ajaxForm(function() {
alert("Thank you for your comment!");
});
});
<form action="/" method="post" id="contact">
</form>
// advanced
$(document).ready(function() {
var options = {
target: '#output1', // target element(s) to be updated with server response
beforeSubmit: showRequest, // pre-submit callback
success: showResponse // post-submit callback
//url: url // override for form's 'action' attribute
//type: type // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
// $.ajax options can be used here too, for example:
//timeout: 3000
};
$('#contact').ajaxForm(options);
});
<form action="/" method="post" id="contact">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment