@vigaset12

Почему не записывается значение в переменную?

const comments__results = $('.comments__results');

var comment_id = '';

function addComment(e){
    e.preventDefault();

    var name = $('.create-comments__input--name').val();
    var surname = $('.create-comments__input--surname').val();
    var message = $('.create-comments__input--message').val();


    $.ajax({
        url: '../../php/comments.php',
        type: 'POST',
        dataType: 'json',
        data: {
            name: name,
            surname: surname,
            message: message
        },

        success: function(result){
            $(".coments__results").html(result.errors);

            if(result.comment[0]['user_id'] == result.user_id){
                $(".comments__body").append(`
                <div class="comments__item">
                    <div class="comments__people">
                        <div class="comments__name">${result.comment[0]['name']}</div>
                        <div class="comments__surname">${result.comment[0]['surname']}</div>
                    </div>
                    <div class="comments__control">
                        <p class="comments__change">Изменить</p>
                        <p class="comments__delete">Удалить</p>
                    </div>
                    <div class="comments__message">${result.comment[0]['message']}</div>
                </div>
                `);
            }

            comment_id = result.comment[0]['id'];
        }
    });
}


function deleteComment(){
    $.ajax({
        url: '../../php/delete_comments.php',
        type: 'POST',
        dataType: 'json',
        data: {
            comment_id: comment_id,
        },            
    });
}


$('.create-comments__button').click(addComment);
$('.comments__delete').click(deleteComment);


В delecomment функции ajax запрос отправляет пустоту! Почему в функции addComment переменная не пополняется данными?
  • Вопрос задан
  • 63 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы