I'm trying to disable a submit button until an ajax function is completed.
Right now, I have only been able to figure out how to disable the button for a specified time when the user is typing.
How can I disable the submit button until the ajax data loads? Thank you.
<script>
    $('#comment_comment').keyup(function() {
      $("#new_comment_button").attr("disabled", true);
      setTimeout(function() { $("#new_comment_button").removeAttr("disabled"); }, 2000);
    });
    $('#comment_comment').preview({ key:'my key', 
      selector : {type:'rich'},
      preview : {
        submit : function(e, data){
          $.ajax({
            dataType: 'script',
            url: this.form.attr('action'),
            type: 'POST',
            data: data
          });
        },
      },
      autoplay : 0,
      maxwidth : 350,
      display : {display : 'rich'}
    });
</script>
 
     
    