当函数成功时,jquery更改页面自动

I'm using header on php when I want to change after function. Now I want to use on jQuery.

if ($('form #response').hasClass('success')) {

    setTimeout("$('form #response').fadeOut('fast')", 5000);
    return window.location = index.php;
}

This line does not work - I want to change page when .hasClass('success') enter code here

return window.location = index.php;

I tried without return again did not work.

Try this:

if ($('form #response').hasClass('success')) {
    setTimeout(function() {
        $('form #response').fadeOut('fast', function() {
            window.location.href = "index.php";
        });
    }, 5000);
}

I changed your settimeout to have a function, which calls the fadeOut on #response, and once that's finished it calls window.location.href and changes it to index.php.

window.location requires quotes around the page. Try this code instead:

window.location = 'index.php';

Instead of setting window.location (which returns a Location object - it's a read-only property), try setting window.location.href. Also, make sure you assign it a string. Here's an example:

window.location.href = "index.php";

Try this

if ($('form #response').hasClass('success')) {
    setTimeout(function() {
        $('form #response').fadeOut('fast');
    }, 5000);
    return window.location = 'index.php';
}//END IF

Also make sure it is wrapped in the $(function() { });