I think you something like this.
HTML
Add this in widget
<a href="https://wordpress.stackexchange.com/questions/254474/javascript:void(0)" id="add_my_fav">Add To Favourite<span id="favCount"></span></a>
Ajax
Add this in template
<?php $nonce = wp_create_nonce('addToFav'); ?>
<script>
jQuery(document).read(function(){
jQuery.ajax({
url: 'http://example.com/wp-admin/admin-ajax.php',
data: {action:"add_to_favourite", secret:"<?php echo $nonce; ?>"},
method: 'POST',
success: function(res){
jQuery('#favCount').html(res);
}
})
})
</script>
PHP
Add this in functions.php
function addToFavourite(){
if(isset($_POST['secret']) && wp_verify_nonce($_POST['secret']))
{
// Add here your code to add favourite
// return new count value
}
}
add_action('wp_ajax_add_to_favourite', 'addToFavourite' );
add_action('wp_ajax_nopriv_add_to_favourite', 'addToFavourite' );