Where is my mistake? html code
<div class="star-rating">
<span class="postid" post-id="52"></span>
<span class="score-bg"></span>
<div class="scores">
<?php for ($i = 1; $i <= 5; $i++): ?>
<div class="score" data-score="<?php echo $i; ?>">
<span class="scoreAbsolute"></span>
</div>
<?php endfor; ?>
</div>
jQuery(document).ready(function ($) {
$(function () {
$(".score").click(function () {
var score = $(this).attr('data-score');
var post = $('.postid').attr('post-id');
$.ajax({
url: post_score.ajaxscript,
method: 'POST',
data: {
'action': 'submit_score',
'postid': post,
'postScore': score,
},
success: function (data) {
console.log(data);
}, error: function (errorThrown) {
alert('nok');
}
});
});
});
});
php code
add_action('wp_ajax_submit_score', 'submit_score');
add_action('wp_ajax_nopriv_submit_score', 'submit_score');
function submit_score()
{
if (isset($_POST['action'])) {
//something
}
wp_die();
}
submit_score
function isn't doing anything, what are you expecting it to do? And can you add some context for what it's meant to do? What are you trying to implement and where are the code snippets you shared located? Use theEdit
link under the tags to update your question so that it's easier to understand what you're asking for