Код js:
$.ajax({
url: 'index.php?route=product/product/review_like&product_id={{ product_id }}',
type: 'post',
data: {
'action': action,
'review_id': review_id
},
success: function(data){
res = JSON.parse(data);
alert('s');
if (action == 'like') {
$clicked_btn.removeClass('review-like-btn');
$clicked_btn.addClass('review-liked-btn');
} else if(action == 'unlike') {
$clicked_btn.removeClass('review-liked-btn');
$clicked_btn.addClass('review-like-btn');
}
// display the number of likes and dislikes
$clicked_btn.siblings('span.review-likes-total').text(res.likes);
$clicked_btn.siblings('span.review-dislikes-total').text(res.dislikes);
// change button styling of the other button if user is reacting the second time to post
$clicked_btn.siblings('.review-disliked-btn').removeClass('review-disliked-btn').addClass('review-dislike-btn');
}
});
Код php:
public function review_like() {
$this->load->language('product/product');
$json = array();
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
// Captcha
if ($this->customer->isLogged() && !empty($this->session->data['user_id'])) {
$this->load->model('catalog/review');
if(isset($this->request->post['action'])){
$review_action = $this->request->post['action'];
$review_id = $this->request->post['review_id'];
$user_id = $this->session->data['user_id'];
$review_total = $this->model_catalog_review->getTotalReviewsLikes($review_action, $review_id, $user_id);
return json_encode($review_total);
}
}
}
}
Ошибка: Uncaught SyntaxError: Unexpected end of JSON input