I\'ve been observing some strange behavior with the following code:
$.fn.submit_to_remote = function() {
// I use .each instead of the .submit directly so
Unbind didn't work for me. This did:
$(document).off('submit');
$(document).on('submit',"#element_id",function(e){
e.preventDefault();
//do something
});
I hope it helps...
In fact unbind() can bring you some troubles if you have some validation and return before submit. Example:
$(document).on('submit',"#element_id",function(e){
e.preventDefault();
$(document).unbind('submit');
var name = $(this).children('input[name="name"]').val();
if( name == 'wrong name')
return;
//do something
});
In this case if you input is 'wrong name' the form will not be submitted and after that, when you put the "right name", the $(document).on('submit'.. will not be triggered, neither the e.preventDefault(); and your form will be submitted in the regular way .