This should be easy for experienced jqueryUI users. What I'd like to achieve is:
- to have one button when the page has just been rendered (and nothing more)
- when this button is clicked, a dialog opens and the dialog content is generated, using AJAX
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:
<script id="user" type="text/html">
<p>
There are following users:
<ul>
{{#users}}
<input type="checkbox" name="user" value="{{ username }}" />{{ fullname }}
{{^last}}<br />{{/last}}
{{/users}}
</ul>
</p>
</script>
<a id="user-btn" class="btn">show users</a>
<a id="dialog-btn" class="btn">show dialog</a>
<div id="dialog-message" title="Select users">
</div>
and this is javascript part:
$(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");
});
});
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).