title: jQuery order of execution using $.load() asynchronous problems (bootstrap modal)
body: <p>I'm having an odd issue with jQuery order of operations.  The code below executes perfectly in ie9 &amp; ie10.  In ie11, firefox, and chrome, it doesn't work at all.  It will execute and open the new window, but load() doesn't fire.  I can put an alert in the event chain and load() works in firefox and ie11...in chrome it still never runs load().  </p>
  
  <p>At first, I thought load's target simply hadn't been added to the DOM yet and that the pause created by the alert gave it time to be created.  I added a sleep timer in the exact same spot to test that theory--it didn't work, and it didn't matter how long the timer was set to.</p>
  
  <p>Any thoughts on this problem would be helpful.  Thanks guys and gals!</p>
  
  <pre><code>    function openWindow(id, which, windowOptions) {
          $('&lt;div&gt;')
          .attr('id', 'GenericWindow')
          .addClass('modal hide fade')
          .html('&lt;div class="modal-header"&gt;&lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;&lt;h3 id="WindowHeader"&gt;Loading...&lt;/h3&gt;'
          + '&lt;/div&gt;&lt;div id="divWindowContent" class="modal-body"&gt;Content!&lt;/div&gt;&lt;div id="WindowButtons" class="modal-footer"&gt;&lt;input type="button" id="btnWindowCancel" value="Cancel" class="btn" data-dismiss="modal" aria-hidden="true" /&gt;'
          + '&lt;input type="button" id="btnWindowSave" value="Save" class="btn btn-info" /&gt;')
          .modal({"keyboard":"true"})
          .on('hidden', function (e) {
              var src = $(e.target);
              if (!src.hasClass('popover-link')) {
                  $('#GenericWindow').remove();
                  clearErrors();
              }
          });
          if (!windowOptions) {
              //THIS IS THE ALERT.
              alert('huh');
  
              var link = '@Url.Action("replace", "Operations")'
              link = link.replace("replace", which);
  
              $('#divWindowContent').load(link, { id: id }, function (response, status, xhr) {
                  if (status == "error") {
                      var msg = "Error loading details : ";
                      $('#divWindowContent').html(msg + xhr.status + " " + xhr.statusText);
                  }
              });
          }
          else {
              if (windowOptions.action) {
                  var action = windowOptions.action;
                      var link = '@Url.Action("view", "controller", new { Area = "MvcMembership" })';
                  if (!$.isNull(action.area))
                      link = link.replace("MvcMembership", action.area);
                  else
                      link = link.replace("/MvcMembership", "");
                  link = link.replace("view", action.view);
                  link = link.replace("controller", action.controller);
  
                  $('#divWindowContent').load(link, action.values, function (response, status, xhr) {
                      if (status == "error") {
                          var msg = "Error loading details : ";
                          $('#divWindowContent').html(msg + xhr.status + " " + xhr.statusText);
                      }
                  });
              }
              else {
                  $('#divWindowContent').html(windowOptions.text);                    
              }
              $('#WindowHeader').html(windowOptions.title);
              if (windowOptions.hideButtons) {
                  $('#WindowButtons').remove();
                  $('#GenericWindow .close').remove();
              }
              $('#GenericWindow').css('width', windowOptions.width);
              $('#GenericWindow').css('height', windowOptions.height);
          }
      }
  </code></pre>
  
  <p>EDIT: I should note that if you are using a function to close any open modal on the page before opening a new modal, appendTo('body') does not work.  You must use the "create-a-variable" solution.  It's also worth noting that creating a variable is much, much faster, especially after the first modal open.</p>