Trying to build in an ajax function that will update_post_meta.
Got this (amongst other js which works just fine) in my js file:
$('.closetask').click(function()
{
var thisid = $(this).attr("id");
console.log(thisid);
var splitx=thisid.split("-");
var target=splitx[1];
var post_meta = "XXXX";
console.log(target);
$.ajax({
type: "post",
url: ajax_vars.url,
data: "action=post-like&nonce="+ajax_vars.nonce+"&post_like=&post_id="+target,
success: function(count)
{
if(count != "already")
{
heart.addClass("voted");
heart.siblings(".count").text(count);
}
}
});
});
Got this in my functions.php file:
function mytheme_wp_enqueue_scripts() {
// wp_enqueue_script('jquery');
wp_enqueue_script('funcs', get_bloginfo('stylesheet_directory') . '/funcs.js', array('jquery'));
wp_localize_script('funcs', 'ajax_vars',
array(
'url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('ajax-nonce')
));
}
add_action( 'wp_enqueue_scripts', 'mytheme_wp_enqueue_scripts' );
problem is, when the click event fires I get this message in firebug:
ReferenceError: ajax_vars is not defined
[Break On This Error]
url: ajax_vars.url,
So it seems as though it’s not picking up the ajax_vars array in the wp_localize_script in the functions file.
Anyone know what I’m doing wrong?