Skip to content

Instantly share code, notes, and snippets.

@franhaselden
Created August 28, 2015 10:56
Show Gist options
  • Save franhaselden/5ab3e5e4874ccbbeff21 to your computer and use it in GitHub Desktop.
Save franhaselden/5ab3e5e4874ccbbeff21 to your computer and use it in GitHub Desktop.
Post form with AJAX
// this is the id of the form
$("#idForm").submit(function() {
var url = "path/to/your/script.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#idForm").serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
return false; // avoid to execute the actual submit of the form.
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment