How to send a message when the button is clicked only once?

Need to send messages at the touch of a button. With a few taps sent multiple times. There were attempts to cancel the handler as the button is pressed, and add back when the message came, to change the class button, clear the field immediately after pressing. But in mobile browsers nothing works and messages as if lining up, and then come all. How can I make so that the message is sent only once?
July 12th 19 at 16:51
3 answers
July 12th 19 at 16:53
About this pattern:
var sending = false;

$(".button").on("click", function () {
 if (sending) {
return;
}

 sending = true;

$.ajax({
 // send data
 success: function (data) {
 sending = false;
}
})
});
July 12th 19 at 16:55
The problem was solved by using flags and clearing fields immediately after clicking on mobile browsers work.
July 12th 19 at 16:57
Liked the idea of a "hide button". Alternatively, many developers after you click submit, make it disabled. In this case, press several times will not work. Must operate and on mobile.

Find more questions by tags JavaScriptWeb Development