DanielAttard
DanielAttard

Reputation: 3615

Pause page execution until after jQuery alert is closed, then run function

I have a jQuery $.alert and a .fadeOut(1000) working consecutively, but I dont like the result that I am seeing. I would like to only run the .fadeOut(1000) after the user has closed the $.alert. I know that you can't actually capture the close event of an alert, but can someone suggest a workaround that might accomplish what I am looking for?

Here is the existing ajax call where I am trying to implement the changes:

$.ajax({
url: sURL + "utility/mymethod",
type: "POST",
data: {ClientNum: ClientNum},
dataType: 'json',
success: function(json) {       
if (typeof(json.ClientEmail) != "undefined" && json.ClientEmail !== null && json.ClientEmail !== "") {
    $.confirm("Please call . . . .",                
    function(){ 
        if (json.ClientEmail){
            send_email(json);
        }
    },              
    function(){
        $.msg("Password recovery information has NOT been sent.",
        {header:'Password Not Sent', live:10000});
        $('#ajaxShield').fadeOut(1000);
    })
} else {
    //THIS IS WHERE I WANT THE FADEOUT TO WAIT FOR THE ALERT
    $.alert("There is no email address.")
    $('#ajaxShield').fadeOut(1000);
}; 
}, 
error:function (xhr, ajaxOptions, thrownError){ alert('Problem, Status code:'+xhr.status+', Error:'+thrownError);} 
});

I would like my overlay to remain visible until the user acknowledges the alert message.

Thanks.

Upvotes: 0

Views: 918

Answers (1)

PerryW
PerryW

Reputation: 1436

$.alert is not native JQuery so is probably a plugin operating asynchronously. A google search suggests though that it isn't one of the better known ones.

Simple test...

Change

$.alert("msg")

To

alert("msg")

Does that look like what you are after (alert works synchronously).

If that's more like what you're after, the next stage is to identify how your plugin works (if you want to continue using it)

Upvotes: 2

Related Questions