【问题标题】:How to set delay on the client side before redirect?如何在重定向之前在客户端设置延迟?
【发布时间】:2018-08-28 08:21:57
【问题描述】:

注册用户并点击注册按钮后,在同一页面显示确认邮件的消息,但页面立即重定向,用户没有足够的时间查看该消息。我想在重定向动作之前设置一个延迟(例如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】:

最好的方法是在 JS 而不是 PHP 中实现重定向。例如你可以把这个 JS 代码放到你的 ajax 回调中:

window.setTimeout( function(){
    window.location = "PATH_TO_REDIRECT";
}, 100 );

【讨论】:

    猜你喜欢
    • 2020-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    • 1970-01-01
    相关资源
    最近更新 更多