Answer the question
In order to leave comments, you need to log in
Why does it throw Uncaught SyntaxError: Unexpected end of JSON input?
js code:
$.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');
}
});
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);
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question