title: jqueryUI: initialising dialog content on first click
body: <p>This should be easy for experienced jqueryUI users. What I'd like to achieve is:</p>
  
  <ul>
  <li>to have one button when the page has just been rendered (and nothing more)</li>
  <li>when this button is clicked, a dialog opens and the dialog content is generated, using AJAX</li>
  </ul>
  
  <p>At the moment I've got most of those, but using two distinct jquery UI buttons. I'm using icanhaz, but it should make no difference, since I got this part working fine. This is the html part:</p>
  
  <pre><code>&lt;script id="user" type="text/html"&gt;
      &lt;p&gt;
          There are following users:
          &lt;ul&gt;
          {{#users}}
              &lt;input type="checkbox" name="user" value="{{ username }}" /&gt;{{ fullname }}
              {{^last}}&lt;br /&gt;{{/last}}
          {{/users}}
          &lt;/ul&gt;
      &lt;/p&gt;
  &lt;/script&gt;
  
  &lt;a id="user-btn" class="btn"&gt;show users&lt;/a&gt;
  
  &lt;a id="dialog-btn" class="btn"&gt;show dialog&lt;/a&gt;
  
  &lt;div id="dialog-message" title="Select users"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and this is javascript part:</p>
  
  <pre><code>$(document).ready( function() {
  
      $("#user-btn").click(function() {
          $.ajax({
              type: "GET",
              dataType: "json",
              url: "../php/client/json.php",
              data: {
                  type: "users"
              }
          }).done(function( response ) {
              var element = $('#dialog-message');
              element.append(ich.user(response));
          });
      });
  
      $("#dialog-btn").click(function() {
          $("#dialog-message").dialog().dialog("open");
      });
  });
  </code></pre>
  
  <p>When I click the first button, "show users", it generates the content for the dialog. When I click "show dialog", the dialog is created and opened. I'd jut like to clean it - to call the ajax (and render icanhaz) when clicked, use the rendered html to create the dialog, open the dialog and display (all in one single click).</p>