Heartbeat API: How to access data already enqueued?
I'm having problems when trying to access data that I've queued using the Heartbeat API.
I'm queuing data using wp.heartbeat.enqueue()
. For example:
var data = {
my_key: 'value'
};
wp.heartbeat.enqueue( 'my_handle', data, false );
Then later on in my script, I'd like to access the data I've queued. For example:
$( document ).on( 'click', '#button', function() {
// Here, I want to access the data I've enqueued.
});
I've tried doing the following but that doesn't work:
$( document ).on( 'click', '#button', function() {
var my_data = wp.heartbeat.getQueuedItem( 'my_handle' );
alert( my_data.data.my_key );
});
Hoping someone can suggest where I'm going wrong?
Topic heartbeat-api jquery Wordpress javascript
Category Web