I want to use jQuery.ajax for sending new mark(about article) to database and changind number of marks on page. But I receive bad AJAX response from server.
{"likes":"40","dislikes":"29"}{"success":true,"message":null,"messages":null,"data":[]}
and error:
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 31 of the JSON data
It seems there must not be the second ajax response. But I'm not understand where it have taken.
That is my php code from Joomla plugin.
$marks = plgContentLikesHelper::getMarks($articleID);
$data=array();
$data['likes'] = $marks->likes;
$data['dislikes'] = $marks->dislikes;
echo json_encode($data);
That is my jQuery code from Joomla plugin.
jQuery(document).ready(function(){
jQuery('div.plg-likes > a ').click(function (e) {
var id = jQuery(this).parent('div.plg-likes').attr('id');
var opinion = jQuery(this).attr('id');
jQuery.ajax({
type: "POST",
dataType: "json",
url: "index.php?option=com_ajax&group=content&plugin=likes&format=json",
data: { articleId: id, articleOpinion: opinion },
success: function(data){ /* troubles are here */
alert(data["likes"]);
}
})
return false;
})
})