ASP.NET MVC - How to prevent double click submit with jquery.validate.unobtrusive lib?

后端 未结 9 1154
伪装坚强ぢ
伪装坚强ぢ 2020-12-29 07:47

I need to avoid the double click submitting behavior. I\'m using the client validation with the unobtrusive library. I have the following code for avoiding the double clic:<

9条回答
  •  梦毁少年i
    2020-12-29 08:13

    I was able to fix a similar issue with a couple of lines of code. I prefer this if you don't want to "alert" to user that they double clicked and just silently ignore the second click.

    I just made a global javascript variable that I toggled when my function was executing during a critical section. This kept subsequent function calls from re-executing the same section.

     var criticalSection = false;
    
     SomeOnClickEventFired = function () {
          if (!criticalSection)
          {
                criticalSection = true;
                //Ajax Time
                criticalSection = false;
          }
     }
    

提交回复
热议问题