0

I have a jQuery UI dialog which loads content from another page. The dialog opens the first time, but not a second time. If don't load anything into the dialog it works the second time too.

See the jsFiddle. [It works, the error must be somewhere else]

HTML:

<a class="click" href="form.php">form</a>
<a class="click" href="data.php">data</a>
<a class="click" href="user.php">user</a>
<div id="dialog"></div>

JavaScript:

$(document).ready(function() {
    $("#dialog").dialog({
        autoOpen: false,
        closeOnEscape: true
    });

    $('.click').click(function(event) {
        event.preventDefault();
        $('#dialog').load(this.href);
        $("#dialog").dialog('open');
    });
});​

1 Answer 1

1

Try opening the dialog in the load's complete callback - the load will run async by default, and so it likely won't be complete by the time you hit the open - that might be what's messing it up (though it's hard to say when the example works :-) )

var $dialog;
$(document).ready(function() {
  $dialog = $("#dialog").dialog({
    autoOpen: false,
    closeOnEscape: true
  });

  $('.click').click(function(event) {
    event.preventDefault();
    $dialog.load(this.href, function() {
     $dialog.dialog('open');
    });
  });
});​
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.