switchery
switchery copied to clipboard
Send via Ajax at the click?
Hello
I'm looking for just sent ajax at the time of "Change", it works, but it sends twice the data ...
If I do :
$ ( '# SuivreGeo'). Change (function () { ... $ .ajax ({ method: 'POST', ...
It seems to me that at the moment of "change" it launches two actions giving the current state, then the state changed.
If I put "click" instead of "change" it sends once the information, but in this case the switch status no longer changes :(
How to send directly to Ajax when clicking on the Switch?
Thanks for your help. Have a good day
Try this:
$ ( '# SuivreGeo'). Change (function () {
if ($(this).attr('disabled) == 'disabled') return false;
$(this).attr('disabled', 'disabled');
$.ajax({
...
}).complete(function () {
$(this).removeAttr('disabled')
})
})