iSimpleDesign
iSimpleDesign

Reputation: 403

Jquery delay timeout function?

I am really struglling tring to get this to work what i what is if my php script returns success.

echo success

I want it to should a message that says congratulations its all setup but stay for aleast 5 seconds but it never seems to work i have tried elay etc but still getting issues please help.

here is my code it works but for about a second it then redirects far to quick to read it.

 if($.trim(data) == 'Congratulations'){
setTimeout(function(){
    $('#congrats').fadeIn(1000,function(){
        window.location.href='http://example.co.uk/tour/first-time-users';
    });
},5500);

Upvotes: 0

Views: 2019

Answers (4)

Rodolfo Palma
Rodolfo Palma

Reputation: 2931

The better option I think is:

if($.trim(data) == 'Congratulations'){
    $('#congrats').fadeIn(1000, function() { setTimeout(function(){
        window.location.href='http://example.co.uk/tour/first-time-users';
    }, 5000)});
}

Upvotes: 0

iTSrAVIE
iTSrAVIE

Reputation: 834

Something like this may be helpful :)

setTimeout(function() {
    $('#congrats').fadeIn(1000, function(){
        window.location = 'http://www.examle.com';
    }}
}, 5500);

The timeout needs its own delay.

Upvotes: 0

Shadow Wizzard
Shadow Wizzard

Reputation: 66398

I think that what you need is:

if($.trim(data) == 'Congratulations') {
    $('#congrats').fadeIn(1000);
    window.setTimeout(function() {
        window.location.href = 'http://example.co.uk/tour/first-time-users';
    }, 5500);
}

This will show the congrats div with animation effect then rediret after 5.5 seconds.

Upvotes: 2

Ian Wood
Ian Wood

Reputation: 6573

set time out expects a string as the function...

try

if($.trim(data) == 'Congratulations'){
    setTimeout("function(){
        $('#congrats').fadeIn(1000,function(){
            window.location.href='http://example.co.uk/tour/first-time-users';
        });
    }",5500);
}

Upvotes: 0

Related Questions