I have "a" element which servers as button. It has no href attribute.
I'm using jQuery to achieve very simple thing: on click start ajax request and prevent further clicks. After ajax completes, enable clicking. I don't use form or input button.
var contact= {
send: function() {
$.ajax({
type: "POST",
url: "ws/ContactService.asmx/SendEmail",
data: '{"fromEmail":"' + $("#email").val() + '", "fromName":"' + $('#name').val() + '", "subject":"' + $('#subject').val() + '", "message":"' + $('#message').val() + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function() {
alert("Error");
},
success: function(msg) {
alert(msg.d);
},
complete: function() {
$("#send").text("Send");
}
});
}
};
$(document).ready(function() {
$("#send").("click", function() {
$("#send").text("Sending...");
contact.send();
});
}
);
This works fine, except that I can click on send as many times as I want and every click will produce new ajax request. How to prevent clicks on "a" element while ajax request is in progress?