javascript – How can I fix the html error in the jquery post?-ThrowExceptions

Exception or error:

I am responding by sending a post in jquery. But div also writes when the div is closed and when the div is opened.

enter image description here

I need to leave only after closing
the code I wrote

jQuery(document).ready(function() {
  jQuery(".button").bind("click", function() {

    var name = jQuery('.nameField').val();
    var surname = jQuery('.surnameField').val();
    var age = jQuery('.ageField').val();


      url: "../ajax/db.php",
      type: "POST",
      data: {
        name: name,
        surname: surname,
        age: age
      }, // Передаем данные для записи
      dataType: "json",
      success: function(result) {
        if (result) {
          jQuery('.comments-list div').remove();
          jQuery('.comments-list').append(function() {
            var res = '';

            for (var i = 0; i <; i++) {
              res += '<div class="media last-child"><a class="media-left" href="#">' +[i] + '</a><div class="media-body"><h4 class="media-heading user_name">' +[i] + '<small>' + result.users.age[i] + '</small></h4><p>' + result.users.surname[i] + '<p></div></div><hr class="invis">';
            return res;
        } else {
        return false;
    return false;
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *