ajax jquery update custom field meta value front end

First, you need to output a response in your my_action_callback() function. That response will be available inside your jQuery success callback: function(response){}. At that point it is just a matter of updating the HTML of the page with the new views count.

PHP:

function my_action_callback()
{
    // ...
    echo $views;
    exit;
}

JavaScript:

jQuery.post(ajaxurl, data, function(response) {
    // $(this) refers to the clicked link.
    // You may use another selector too if needed.
    $(this).text(response);
});

Leave a Comment