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 4075874
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:21:14+00:00 2026-05-20T17:21:14+00:00

I’m using the SimpleModal plugin to display a dialog on a site. Within that

  • 0

I’m using the SimpleModal plugin to display a dialog on a site. Within that dialog I have two links that will perform AJAX requests and the response from those requests should replace the current contents of the dialog. I’m trying to keep things as flexible as possible so that if I want to be able to load different responses into the dialog later on, it will just work.

In one function I open the dialog:

$('div.modal').modal(
{
    minWidth: width,
    minHeight: height,
    onOpen: modal_onOpen,
    onClose: modal_onClose
});

The onClose callback looks like this:


function modal_onClose(dialog)
{
    dialog.container.fadeOut('slow', function()
    {
        dialog.data.hide();

        if(reload_dialog)
        {
            data = ajax_page_load(reload_url, false, false);

            if(data.statusText == 'OK')
            {
                dialog.container.width(reload_width);
                dialog.container.height(reload_height);
                $.modal.setPosition();

                $('div.modal div.container').html(data.responseText);
                dialog.data.show();
                dialog.container.fadeIn('slow', function()
                {
                    $('a.simplemodal-close').bind('click', function()
                    {
                        $.modal.close();
                    });
                });
            }

            reload_dialog = false;
        }
        else
        {
            dialog.overlay.slideUp('slow', function()
            {
                $.modal.close();
            });
        }
    });
}

And when I want to load something new into the dialog I have this:


var reload_dialog = false;
var reload_url;
var reload_width;
var reload_height;

function load_dialog(url, width, height)
{
    reload_dialog = true;

    reload_url = url;
    reload_width = width;
    reload_height = height;

    $.modal.close();
}

Now, all of the code above functions. But Im concerned that I have way over complicated things. Here’s why:

In modal_onClose I was forced to rebind the close handler to the anchor inside of the dialog. If I don’t bind there I am unable to close the dialog AFTER the AJAX request even though the anchor tag displays properly inside of the dialog. Also after binding the anchor tag it functions but ignores the onClose animations that I have set.

As a result of all this I get the feeling that I’ve not taken the best approach to the solution.

Has anyone completed something similar to this? Any tips?

Thanks in advance, I know there’s a lot of info here 🙂

  • 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-20T17:21:14+00:00Added an answer on May 20, 2026 at 5:21 pm

    I solved this so I thought I’d leave a response for anyone else looking.

    Basically my problem boiled down to calling $.modal.close() when I shouldn’t have been.

    Initially when I wanted to reload the dialog I called $.modal.close() and performed my reload inside of the onClose() callback. By calling $.modal.close() it would seem that I was stripping the close event handler and so when I reloaded the dialog things were breaking.

    To fix the issue I removed the reload request from the onClose() callback and just handled everything inside a regular function. When I was using the callback I was making use of the returned dialog object to perform animations. With this new approach I can achieve the same result by targeting $(‘#simplemodal-container’) instead.

    TL;DR – The code below allows me to load new data into an open dialog via AJAX while also being able to re-size and re-position the dialog.

    Code to open a dialog:

    
    function pop_dialog(url, width, height)
    {
        $('div.modal').modal(
        {
            minWidth: width,
            minHeight: height,
            onOpen: function(dialog)
            {
                //Animate the overlay
                dialog.overlay.slideDown('slow', function () 
                {
                    //Make sure the contents of the dialog are showing
                    dialog.data.show();
    
                    //Preload
                    $('.dialog-preloader').show();
                    $('div.modal img.logo').show();
    
                    //Fade in preloader display and perform AJAX request
                    dialog.container.fadeIn('fast', function()
                    {
                        data = ajax_page_load(url, false, false);
    
                        //On success, show dialog contents
                        if(data.statusText == 'OK')
                        {
                            $('div.modal div.container').html(data.responseText);
                            $('.dialog-preloader').hide();
                        }
                    });
                });
            },
            onClose: function(dialog)
            {
                //Fade out the dialog
                dialog.container.fadeOut('slow', function()
                {
                    //If we're closing the dialog, animate the overlay off.
                    dialog.overlay.slideUp('slow', function()
                    {
                        //Clean up the mess.
                        $.modal.close();
                    });
                });
            }
        });
    }
    
    

    Code to ‘reload’ the dialog

    
    function load_dialog(url, width, height)
    {
        //Hide the dialog
        $('#simplemodal-container').fadeOut('slow', function()
        {
            //Hide the dialog contents and show preloader
            $('div.modal div.container').hide()
            $('.dialog-preloader').show();
    
            //Set the new width
            $('#simplemodal-container').width(width);
            $('#simplemodal-container').height(height);
            $.modal.setPosition();
    
            //Fade container back in with preload message
            $('#simplemodal-container').fadeIn('slow', function()
            {
                //Perform AJAX request to load new dialog
                data = ajax_page_load(url, false, false);
    
                //On success, show dialog contents
                if(data.statusText == 'OK')
                {
                    $('div.modal div.container').html(data.responseText);
                    $('.dialog-preloader').hide();
                    $('div.modal div.container').show();
                }
            });
        });
    }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.