如何在重定向之前设置客户端的延迟?

问题描述 投票:0回答:1

注册用户并单击注册按钮后,将显示一条消息以确认同一页面上的电子邮件,但页面立即重定向,用户没有足够的时间查看该消息。我想在重定向操作之前设置延迟(例如5秒),之后,将执行重定向操作。

    if ( is_wp_error($user_id) ){
        throw new Exception($user_id->get_error_message() , 401);
    }

    $data     = get_userdata( $user_id );
    $userdata = QA_Member::convert($data);
    // generate new nonces
    $msg = ae_get_option( 'user_confirm' ) ? __('You have registered an account successfully but are not able to join the discussions yet. Please confirm your email address first.', ET_DOMAIN) : __('You are registered and logged in successfully.', ET_DOMAIN) ;
    $response = array(
        'success'       => true,
        'code'          => 200,
        'msg'           => $msg,
        'data'          => $userdata,
        'redirect'      => apply_filters( 'qa_filter_redirect_link_after_register', home_url() )
    );

} catch (Exception $e) {
    $response = array(
        'success' => false,
        'code'    => $e->getCode(),
        'msg'     => $e->getMessage()
    );
}
wp_send_json( $response );
     }
php wordpress delay
1个回答
0
投票

执行此操作的最佳方法是在JS中而不是在PHP中实现重定向。例如,您可以将此JS代码放到ajax回调中:

window.setTimeout( function(){
    window.location = "PATH_TO_REDIRECT";
}, 100 );
© www.soinside.com 2019 - 2024. All rights reserved.