I solved that issue on my own.
The following code solved.
jQuery(document).ready(function($) {
$('.faq-item').click(function() {
var faq_post_id = $(this).data('post-id');
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
var xhr = new XMLHttpRequest();
xhr.open('POST', ajaxurl);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log('Post views updated. ID: ' + faq_post_id);
}
};
xhr.send('action=update_post_views&post_id=' + faq_post_id);
});
});
function update_post_views() {
$post_id = $_POST['post_id'];
pvc_get_post_views( $post_id, 'total' );
$post_views = ($post_views == '') ? 1 : $post_views + 1;
pvc_update_post_views( $post_id, $post_views);
wp_die();
}
add_action('wp_ajax_nopriv_update_post_views', 'update_post_views');