douweidao3882
2015-12-02 11:51Wordpress ajax没有在functions.php中调用函数
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.
- 点赞
- 回答
- 收藏
- 复制链接分享
2条回答
为你推荐
- Ajax在WordPress中不起作用
- ajax
- wordpress
- php
- jquery
- 2个回答
- Wordpress ajax没有在functions.php中调用函数
- ajax
- wordpress
- php
- jquery
- 2个回答