Hello! When receiving data, ajax pops up a window with the error:
JS part:
$('#btn').click(function(){ $comment = $('#comment').val(); $id = $('#comment').attr('name'); if($comment!=''){ $.ajax({ type: 'post', url:'file', data:{comment:$comment, id:$id}, dataType:'json', error: function(text, error, key, value) { alert('Ошибка AJAX: ' + text + ' | ' + error +' | '+ key, + value); }, success: function(data){ $('#test').prepend(data.author + data.comment + data.date); } }); $('#comment').val(''); $('.so-hard').removeClass('active'); } });
php part:
if(isset($_POST['comment']) && isset($_POST['id'])){ $text = htmlspecialchars($this->input->post('comment')); $id = $this->input->post('id'); $author = 'Test'; $date = date('dmY H:i'); $this->data_m->add_comment($id,$author,$text,$date); echo json_encode(array('author'=>$author, 'comment'=>$text, 'date'=>$date)); }
Yesterday everything worked fine, today a bug began to pop up, as far as I remember, I did not change anything in the code! Data is added to the database normally, but the data cannot be inserted into the page, apparently due to this error. In Firefox in a pop-up window it gives out
AJAX Error: [object Object] | parsererror | SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data.
I looked at the response from the server, such is the line at the very top of the page: {"author":"Test","text":"hfghfgh","date":"18-01-2014 23:29"}