switchery icon indicating copy to clipboard operation
switchery copied to clipboard

Send via Ajax at the click?

Open OursEnSki opened this issue 6 years ago • 1 comments

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

OursEnSki avatar Mar 13 '18 17:03 OursEnSki

Try this:

$ ( '# SuivreGeo'). Change (function () {
    if ($(this).attr('disabled) == 'disabled') return false;
    $(this).attr('disabled', 'disabled');
    $.ajax({
      ...
    }).complete(function () {
      $(this).removeAttr('disabled')
    })
})

tsuijie avatar May 23 '18 09:05 tsuijie