Good afternoon. Faced json. Not strong here, I revised the code more than once, tried it differently, I registered it without variables, without processing. Data is sent to the server. The method processes correctly and $json['total'] - has the right value. But success: function(data) does not work. Made check on $.ajaxSetup - Requested JSON parse failed. what's wrong - I can not understand (
public function like(){ if($_POST['track_id']) { $json = array(); $liked = $this->model->like($_POST['track_id']); $res = $this->model->count_like($_POST['track_id']); $json['total'] = (int)$res[0]['count_like']; echo json_encode($json); } } function addLike(track_id) { $.ajax({ type: 'post', url: '/tracks/like', data: 'track_id=' + track_id, dataType : "json", success: function (data) { alert("1"); } }); }