Skip to content

Instantly share code, notes, and snippets.

@andrIvash
Created October 25, 2015 10:32
Show Gist options
  • Save andrIvash/457c24d4c769652c7964 to your computer and use it in GitHub Desktop.
Save andrIvash/457c24d4c769652c7964 to your computer and use it in GitHub Desktop.
Post form data
function postFormData(form, successCallback) {
var
host = form.attr('action'),
reqFields = form.find('[name]'),
dataObject = {};
if (!host) {
console.log('set action attribute to your form, you fool!!');
}
reqFields.each(function(){
var
$this = $(this),
value = $this.val(),
name = $this.attr('name');
dataObject[name] = value;
});
$.post(host, dataObject, successCallback);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment