Jump to content
IPS Community Suite 简体中文
Sign in to follow this  
ipscn

WordPress Heartbeat using Javascript

Recommended Posts

引入PHP脚本

wp_enqueue_script( 'heartbeat' );
wp_register_script('acg-faceid', FACE_ID_PLUGIN_URL . 'assets/js/faceid-0.9.js',array('jquery','heartbeat' ),false,true);

Jq

    $(document).on('heartbeat-send', function(event, data) {

        data.acg_faceid = {
            'uid': faceId.uid
        };

        console.log(data);
    });

    $(document).on('heartbeat-tick', function(event, data) {

        console.log('心跳响应');

        if (data.acg_faceidd) {
            console.log(data.acg_faceidd);
            console.log('data.acg_faceidd.v');
            console.log(data.acg_faceidd.v);
            if (true === data.acg_faceidd.v) {
                $('#acg-faceid-qr-c').remove();
                $('#place_order').removeAttr('disabled');

              if (wp.heartbeat.isQueued('acg_faceid')) {
                  wp.heartbeat.dequeue('acg_faceid');
              }
            }

        }



    });

 

jQ中wp.heartbeat可用的方法

connectNow: r()
dequeue: w(a)
disableSuspend: s()
enqueue: u(a,b,c)
getQueuedItem: x(a)
hasConnectionError: q()
hasFocus: p()
interval: t(a,b)
isQueued: v(a)

interval 单位是秒,应在15-120之间。

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×