0

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);
1
  • That code you've got will fade in the element "congrats" after five and a half seconds. What doesn't work? What are the "issues"? Commented Jan 13, 2011 at 14:53

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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);
}

3 Comments

Why do people still keep passing in strings into the setTimeout funciton? I see this so often.
That's a terrible bad practice. Please don't even recommend it.
@Šime Vidas gooood question ... some weird mix between lambda and giving the function name
0

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.

1 Comment

i dont want congrats to fadeIn for 5 secs i want it to show immediately but wait 5 secs before the page redirects.
0

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)});
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.