Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7569723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:14:17+00:00 2026-05-30T15:14:17+00:00

I have problem with Jquery UI dialog,when i click the button the first time,

  • 0

I have problem with Jquery UI dialog,when i click the button the first time, it does show the dialog but not in modal dialog, but when you click it the second time, it show it correctly as a modal dialog

$('.ajax').live('click', function ()
{
    var url = "/home/test";
    var dialog = $("#dialog");

    $( "#dialog" ).dialog({
        height: 140,
        title:"Title",
        modal: true
    });


    if ($("#dialog").length == 0)
    {
        dialog = $('<div id="dialog"></div>').appendTo('body');
    }
    $.ajax(
        {
            url: url,
            beforeSend: function (jqXHR, settings)
            {
                //show an animated gif
            },
            complete: function (jqXHR, textStatus)
            {
                //hide the animated gif
            },
            success: function (data, textStatus, jqXHR)
            {
                dialog.dialog().html(data);
            },
            error: function (jqXHR, textStatus, errorThrown)
            {
                dialog.dialog().html("An error occured...");
            }
        });

    return false;
});

Here is the code for the button click event

<button class="ajax">open dialog</button>

see this link to test the above code

http://jsfiddle.net/jRPfu/13/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:14:18+00:00Added an answer on May 30, 2026 at 3:14 pm

    Here is how I would do it.

    1. You declare a variable dialog so use it afterwards

    2. Check directly if a #dialog element was found with dialog.length. In case it’s empty, create your markup

    3. Initialize your dialog with the option autoOpen: false. This way the dialog is initialized once and for all but it will remain hidden.

    4. In your ajax callbacks, call the open method to show the dialog with dialog.dialog('open'). As a side note, it seems more logic to set the content of the dialog and then open it.

    Further reading:

    • autoOpen option
    • open method

    Here’s the modified code:

    var dialog = $("#dialog");
    
    if (dialog.length == 0) {
    
        dialog = $('<div id="dialog"></div>').appendTo('body');
    
        dialog.dialog({
            height: 140,
            title: "Title",
            modal: true,
            autoOpen: false
        });
    
    }
    
    $.ajax({
        url: url,
        ...
        success: function(data, textStatus, jqXHR) {
            dialog.html(data).dialog('open');
        },
        error: function(jqXHR, textStatus, errorThrown) {
            dialog.html("An error occured...").dialog('open');
        }
    });
    

    DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with Jquery UI modal dialogs. I have modal dialog (dialogA),
I have a problem with Jquery function getJSON, the action url does not trigger
I have a problem with the jquery-ui dialog box . The problem is that
I have blinking text modal dialog box and slideshow with jquery. They working just
I have the following jQuery code to execute when I click a button $('#substat').click(function()
I have a jQuery UI dialog that opens when the user clicks a button,
I have setup a jQuery UI modal dialog to display when a user clicks
I have a jquery modal confirm-box, I added a register and login button (
I have a bit of a problem with a jQuery dialog and the way
I have a problem: after enable button, it look like enabled but isn't clickable.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.