0
我正試圖在wordpress後端實施星級評分。我已經成功實施了這個系統。現在,我試圖將星級評分添加到數據庫,而使用admin-ajax單擊這些星星。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電話會去。請幫助我,我k印度新阿賈克斯。
什麼是'update_post_meta'($ post_id,'starrating',$ _ POST ['rating']);' 只需'echo'那裏你想要什麼作爲迴應 –
更新函數更新在後端選擇了多少顆星星並轉換它轉換爲int值並將其存儲在「starrating」 – Jackson
中,您需要在主題的functions.php上創建自定義ajax_action: https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action) – Bazaim