/ Published in: jQuery
Bind Submit form Event handler after previously attached handler
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var form =jQuery('form[name="testform"]'); var events = form.data("events"); var previous_submit = events.submit[0]['handler']; form.unbind('submit', events.submit[0]); form.bind('submit', function() { if (previous_submit.call(this)==false) return false; var data = {}; jQuery(this).find('input[name],select[name],textarea[name]').each( function(index, input) { data[input.name] = input.value; }) $.when( $.ajax ( { type : 'POST', url : location.protocol+'//'+location.hostname+location.pathname, data: data, success: onSuccess }) ).done (function() { console.log('form submitted'); }) });