Skip to content
Advertisement

jQuery click makes multiple AJAX calls

I’ve got multiple jQuery scripts working together. One binds the click actions to the elements, another handles the specific functions.

Although trying to stop multiple calls in different ways i can still fire off two calls by clicking really fast.

After the success call rebinds the action its also possible to double the number of calls each time it comes back, but this seems to be the consequence of being able to call it twice in the first place.

Any suggestions to make sure takeAction can only be called upon once?

Here’s a snippet of my code:

Action-click binder:

JavaScript

Battle functions:

JavaScript

And the HTML buttons that get the click event:

JavaScript

The problem seems to be with re-assigning the click after the AJAX call. In that small timeframe I am able to launch two calls.

Advertisement

Answer

You can disable the button after clicking and re-enable it after AJAX call:

Action-click binder:

JavaScript

Battle functions:

JavaScript
Advertisement