I have an HTML markup like following:
<div id="picing-selection" class="disableMe">
<a class="upgradeSub" value="@ViewBag.Id">
Upgrade <i class="fa fa-money"></i>
</a>
</div>
And the onclick event defined looks like following:
$(document).on("click", ".upgradeSub", function() {
$.post("/Subscription/UpgradeSubscription", {
SubID: $(this).attr("value")
}).done(function(data) {
if (data == "Ok") {
$(this).prop('disabled', false);
window.location.href = "/Index/Success";
} else if (data == "Error") {
alert("Something went wrong");
}
});
});
I want to disable any future onclick event until the server responds with status "ok" or "Error"
I've tried something like:
$(document).on("click", ".upgradeSub", function() {
$(this).prop('disabled', true);
// After this goes the post to server
});
But this didn't work... I can still keep clicking and the jquery will keep posting requests to the server...