Lukáš Ježek
Lukáš Ježek

Reputation: 75

JQuery dialog close and reload page

does anybody please know how I should close the dialog with fade effect and reload the page only after it is closed. Unfortunately location.reload occurs immediately without waiting for dialog being closed.

function show_dialog_ok()
{
$("#dialog_ok").text("Your message was sent");
$("#dialog_ok").dialog({
  hide: {effect: "fade", duration: 2000}, modal: true
});

setTimeout(function() { $("#dialog_ok").dialog('close'); }, 2000);

location.reload();
}

Upvotes: 0

Views: 254

Answers (2)

Leonardo Delfino
Leonardo Delfino

Reputation: 1498

Use the complete callback to call realod after animation is complete:

function show_dialog_ok()
{
    $("#dialog_ok").text("Your message was sent");
    $("#dialog_ok").dialog({
      hide: {
        effect: "fade", 
        duration: 2000,
        complete: function() {
            location.reload();
        }
      }, modal: true
    });

    setTimeout(function() { $("#dialog_ok").dialog('close'); }, 2000);
}

Upvotes: 0

adeneo
adeneo

Reputation: 318352

How about reloading at the same time you're closing the dialog, inside the timeOut

function show_dialog_ok() {
    $("#dialog_ok").text("Your message was sent");
    $("#dialog_ok").dialog({
        hide: {effect: "fade", duration: 2000}, modal: true
    });

    setTimeout(function() { 
        $("#dialog_ok").dialog('close'); 
        location.reload();
    }, 2000);
}

Upvotes: 1

Related Questions