I'm trying to create some modal windows that load in their content dynamically using AJAX with the jQuery UI dialog widget. The idea is that dialog will ONLY exist on the page when the user requests something and then be removed again when the user clicks the close button. However with my current code I have two problems: 1.) the dialog exists on the page before being requested from what I can tell 2.) when a user closes the modal it can't be opened again unless they refresh the page...
I have the following code in my app:
$('.ajax').live('click', function()
{
var url = this.href;
var dialog = $("#dialog");
if ($("#dialog").length == 0)
{
dialog = $('<div id="dialog"></div>').appendTo('body');
}
dialog.load(
url,
{},
function(responseText, textStatus, XMLHttpRequest)
{
dialog.dialog();
}
);
return false;
});
Any help would be much appreciated. Thanks