Skip to content

Instantly share code, notes, and snippets.

@mediaupstream
Created May 6, 2012 04:28
Show Gist options
  • Select an option

  • Save mediaupstream/2612896 to your computer and use it in GitHub Desktop.

Select an option

Save mediaupstream/2612896 to your computer and use it in GitHub Desktop.
ajax post with jQuery
$('#myCoolForm').submit(function(e){
e.preventDefault(); // ensures we don't actually submit the form like normal
var url = $(this).attr('action'); // grabs the html form action attribute, eg our post url
var data = $(this).serialize(); // this will take all the form elements and serialize them into a querystring to be posted
$.post( url, data, function(data, textStatus){
// do something cool here
console.log(data);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment