javascript - How to make button unclickable if Ajax has not received a response -
this question has answer here:
- disable button while ajax request 5 answers
what want is, when user clicks button , ajax waiting response, button should unclickable until ajax receives response. how can this?
script:
$(document).ready(function () { $('#sendrestorepass').click(function (e) { e.preventdefault(); var data = {}; data.restoreemail = $('#restoreemail').val(); data.mypass = $('#mypass').val(); $.ajax({ type: "post", url: "view/restorepass.php", datatype: "json", data: data, cache: false, success: function (response) { if (number(response) === 0) { $("#dialog-confirm-restoreemail-0").dialog("open"); $('#restoreemail').val(''); } if (number(response) == 1) { $("#dialog-confirm-restoreemail-1").dialog("open"); } if (number(response) == 2) { $("#dialog-confirm-restoreemail-2").dialog("open"); } } }); return false; }); });
when run function set button disabled with:
.attr('disabled','disabled');
when ajax completes, set:
.attr('disabled', false);
Comments
Post a Comment