【发布时间】:2020-12-03 13:33:45
【问题描述】:
我写了一些通过heartbeat-send JS 事件连接到 WordPress 心跳的东西。
但是,为了测试事情,我会坐下来等待。
我尝试从控制台运行jQuery(document).trigger("heartbeat-send");,但没有成功。
我不确定如何随时触发心跳,或者是否有可能:)
【问题讨论】:
我写了一些通过heartbeat-send JS 事件连接到 WordPress 心跳的东西。
但是,为了测试事情,我会坐下来等待。
我尝试从控制台运行jQuery(document).trigger("heartbeat-send");,但没有成功。
我不确定如何随时触发心跳,或者是否有可能:)
【问题讨论】:
请参考下面的链接对你有帮助
https://developer.wordpress.org/plugins/javascript/heartbeat-api/
jQuery(document).on('heartbeat-tick', function(event, data) {
// Check for our data, and use it.
if (!data.myplugin_customfield_hashed) {
return;
}
alert('The hash is ' + data.myplugin_customfield_hashed);
});
【讨论】:
tick 不是接收事件吗?您如何强制心跳发生在 WordPress 设置的时间间隔之外?一个蹩脚的例子是:我想在单击按钮时触发心跳。你会怎么做?有可能吗?