WordPress Heartbeat API cannot parse data

Question

I had a working heartbeat connection that would update a user’s personal (custom) options that I have created. The heartbeat would change from their frontend dashboard to the screen that reflects their profile in another location.

However, I am now getting a parsing error in the JSON that is being passed, and for the life of me cannot get the error to output to debug. I only recently updated to the latest jQuery and WordPress versions, but even when I roll back to the older working one I am still getting the errors.

This is my frontend for the user:

// AJAX form
<input name="mb_user_id" value="22">
<input type="radio" name="mb_user_location" value="1">
<input type="radio" name="mb_user_location" value="2">

// the heartbeat
$(document).ready( function() {

    $(document).on( "heartbeat-send", function( e, data ) {
        data.mb_user_id = $('input[name="mb_user_id"]').val();
    });

    $(document).on( "heartbeat-tick", function( e, data ) {
        data.mb_user_location && $("input#mb_user_location" + data.location ).prop( "checked","checked" );
    });

    $(document).on( "heartbeat-error", function( e, jqXHR, textStatus, error ) {
        console.log( textStatus + ' ----------- ' + error );            
    })
});

// php
function mb_heartbeat_received( $response, $data ) {

    if( empty($data['mb_user_id']) || !is_numeric($data['mb_user_id']) ) {
        return $response;
    }

    $mb_userid = absint($data['mb_user_id']);

    $response['mb_user_location'] = get_user_meta( $mb_userid, 'mb_user_location_current', true );

    return $response;
}

I am getting the error:

SyntaxError: JSON Parse error: Unexpected identifier "SyntaxError"

0
, , , markb 4 years 2019-09-26T01:08:47-05:00 0 Answers 96 views 0

Leave an answer

Browse
Browse