Answer the question
In order to leave comments, you need to log in
How to correctly implement sending data to the server not from a form in Yii2?
I am making a tree-like comments module and there is a need for a rating.
The comment template itself looks something like this:
<li class="<?= $class ?>" id="comment-<?= $model['comm_id'] ?>" data-parent="<?= $model['parent_comm_id'] ?>">
...
<div class="vote">
<a class="upvote"> </a>
<a class="downvote"> </a>
</div>
...
</li>
var csrf_param = $('meta[name=csrf-param]').attr("content");
var csrf_token = $('meta[name=csrf-token]').attr("content");
var commentId = $(this).closest('.comment').attr('id').split('-');
commentId = commentId[1];
$widget.on('click.comments', '.upvote', function() {
var data = {'_csrf':csrf_token , 'type':'rating', 'vote':'up', 'comm_id':commentId};
//console.log(data);
requestToServer($(this), '/comments/default/vote', 'POST', data, successVote);
return false;
});
$widget.on('click.comments', '.downvote', function() {
var data = {'_csrf':csrf_token , 'type':'rating', 'vote':'down', 'comm_id':commentId};
requestToServer($(this), '/comments/default/vote', 'POST', data, successVote);
return false;
});
Answer the question
In order to leave comments, you need to log in
url can be written in the link itself
<a href="/comments/default/vote" class="upvote"> </a>
<script>
var ajax = {
voteUrl: '/comments/default/vote',
...
};
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question