Here's what I try to do : calling a function in my theme functions.php from the front of my theme.
So, on the front :
$(document).on('click','.btn-vote',function(e){
e.preventDefault();
var $that = jQuery(this);
var id = $that.attr('data-id');
var data = {
'action': 'voteIncrementer',
'id': id
};
jQuery.post(ajaxurl, data,function(response){ // ajaxurl is defined in footer.php > var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
console.log(response);
$that.find('.vote-count').html(response);
});
});
And the related function in functions.php :
add_action("wp_ajax_voteIncrement", "voteIncrement");
add_action("wp_ajax_nopriv_voteIncrement", "voteIncrement");
function voteIncrement(){
echo 'hello';
die();
}
Quit simple right ? But the thing is : in my JS, the log returns 0 (that means that wp-ajax can't find my function).
What I am missing ?