【发布时间】:2017-07-11 13:00:53
【问题描述】:
我正在尝试在 wordpress 后端实现星级评分。我已经成功实现了系统。现在我正在尝试将星级评分添加到数据库中,同时使用 admin-ajax 点击星星。
这是我的html:
<li name="star" value="one" onmouseover="highlightStar(this);" onmouseout="removeHighlight();" onclick="addRating(this);">
鼠标点击它调用addrating函数,我写了我的ajax,这是我的ajax代码:
function addRating(obj) {
$('ul.rating li').each(function(index) {alert("hello");
$(this).addClass('selected');
var rate=$('#rating').val((index+1));
var postid=$(this).data('postid');
if(index == $("ul.rating li").index(obj)) {
return false;
}
$.ajax({ url:"<?php echo site_url().'/wp-content/themes/options-framework-theme-master/register_ajax.php';?>",
type:'post',
data:{
postid:'postid',
rate:'rate'},
success: function(result){
alert(result);
}
}
});
});
}
这就是 ajax 调用的去向:
<?php
$id = $post['postid'];
update_post_meta($post_id,'starrating',$_POST['rating']);
?>
问题是点击星星时没有 ajax 调用正在进行。请帮助我,我是 ajax 的新手。
【问题讨论】:
-
update_post_meta($post_id,'starrating',$_POST['rating']);是什么echo那里有你想要的回应 -
更新函数更新后端选择了多少颗星并将其转换为int值并将该值存储在“starrating”中
-
你需要在你的主题的functions.php上创建一个自定义的ajax_action:codex.wordpress.org/Plugin_API/Action_Reference/…