I wrote an ajax call in the front end. I wrote the server side in functions.php
function updateCont(){
global $wpdb;
$post_id = $_POST['post_id'];
$key = $_POST['key'];
$value = $_POST['value'];
update_post_meta($post_id, $key, $value);
echo $value;
die();
}
add_action('wp_ajax_updateCont', 'updateCont');
add_action('wp_ajax_nopriv_updateCont', 'updateCont');
My jquery is as follows
jQuery.ajax({
type:"POST",
url: "<?php echo admin_url('admin-ajax.php'); ?>",
data: {"post_id":<?php echo get_the_ID();?>, "key":"top_left_content", "value":"new content"},
success:function(data){
console.log(data);// is 0
}
});
However, the data returned from the ajax call is always "0" When I searched for it, people say my function is not loaded into wordpress. I don't understand what to do here.