title: How can I implement a wait mechanism until receiving confirm dialog response?
body: <p>Here is my code:</p>
  
  <pre><code>    $(function () {
          $(document).on('click', '.fa-times', function(e){
              e.stopPropagation();
  
              var result = ConfirmDialog('Are you sure?');
              if (result) {return false}
  
              var row = $(this).closest('tr');
              row.css('opacity','0.3');
              var word = $(this).closest('td').siblings('.word').text();
              $.ajax({
                  url :  '../../te_addStopWord',
                  type : 'GET',
                  data: {word : word},
                  dataType : 'JSON',
                  success : function () {
                      row.remove();
                  }, // success
                  error : function ($a,$b,$c) {
                      alert($b);
                      row.css('opacity','1');
                  }
              }); // ajax
          })
  
  
          function ConfirmDialog(message) {
              $('&lt;div&gt;&lt;/div&gt;').appendTo('body')
                      .html('&lt;div&gt;&lt;h6&gt;'+message+'?&lt;/h6&gt;&lt;/div&gt;')
                      .dialog({
                          modal: true, title: 'Delete message', zIndex: 10000, autoOpen: true,
                          width: 'auto', resizable: false,
                          buttons: {
                              Yes: function () {
                                  $(this).remove();
                                  return true;
                              },
                              No: function () {
                                  $(this).remove();
                                  return false;
                              }
                          },
                          close: function (event, ui) {
                              $(this).remove();
                          }
                      });
          };
  
  
      })
  </code></pre>
  
  <p>But my code run that ajax request without waiting for the response of <code>ConfirmDialog(message)</code> function. How can I force it to wait?</p>