javascript - How to make button unclickable if Ajax has not received a response -


this question has answer here:

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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -