Márk Cserepes
Márk Cserepes

Reputation: 85

Prevent jQuery on fire multiple times

I have a web application which requires all data to be saved immediately.

I use the following lines to trigger the ajax call:

$('#form_global').on("change", function(e) {
    e.preventDefault();
    transaction_save();
});

My problem is that there are other events, which changes multiple inputs and the multiple input change triggers the ajax call multiple times.

Is there any way to prevent .on("change") to be fired multiple times?

Upvotes: 3

Views: 156

Answers (1)

Rahul
Rahul

Reputation: 21

You can add below code after e.preventDefault()

e.stopImmediatePropagation();

$('#form_global').on("change", function(e) {
    e.preventDefault();
    e.stopImmediatePropagation();
    transaction_save();
});

Here's a link

Upvotes: 2

Related Questions