Last active
August 29, 2015 14:21
-
-
Save khoand0000/6586222d63ff3089f537 to your computer and use it in GitHub Desktop.
submit form by ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { // wait for the DOM to be ready | |
$('#foo').submit(function() { // bind function to submit event of form | |
$.ajax({ | |
type: $(this).attr('method'), // get type of request from 'method' | |
url: $(this).attr('action'), // get url of request from 'action' | |
data: $(this).serialize(), // serialize the form's data | |
success: function(response) { | |
// if everything goes well, update the div with the response | |
$('#result').html(response); | |
} | |
}); | |
return false; // important: prevent the form from submitting | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment