Jquery .off And Then Restore It To On
Solution 1:
Calling .off() with no arguments removes all handlers attached to the elements. Specific event handlers can be removed on elements by providing combinations of event names, namespaces, selectors, or handler function names.
Attach an event handler function for one or more events to the selected elements. And it must have arguments -
.on( events [, selector ][, data ], handler )
Instead of binding and unbinding, I suggest you use button disabling logic : .prop('disabled')
$('#submitBtn').prop('disabled',true) //disable
$('#submitBtn').prop('disabled',false) //enable
Note : The ID selector is written as $('#submitBtn')
and not $(#submitBtn)
Solution 2:
You are removing the event so when you call on()
you need to specify which event since it won't know about it.
$('#submitBtn').on('click', someFn);
You could also disable the button to prevent multiple submits and then remove the disabled attribute in your ajax success handler
Post a Comment for "Jquery .off And Then Restore It To On"