M
M
Maxim Iralov2020-05-17 16:23:43
PHP
Maxim Iralov, 2020-05-17 16:23:43

Why ajax request outputs undefined?

I have an ajax request to update data in a MySQL table

//запрос на обновление ajax

        $("body").on("click", ".activeBtn", function(e) {
            e.preventDefault();
            var tr = $(this).closest('tr');
            act_id = $(this).attr('id');
            Swal.fire({
                title: 'Вы уверены, что хотите подтвердить запись?',
                text: "Данное действие нельзя отменить!",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Да, подтвердить!',
                cancelButtonText: 'Не подтверждать!'
            }).then((result) => {
                if (result.value) {
                    $.ajax({
                        url: "../php/action.php",
                        type: "POST",
                        data: { act_id: act_id },
                        success: function(response) {
                            alert(response.error);  
                            tr.css('background-color', '#ff6666');
                            Swal.fire(
                                'Удалено!',
                                'Запись успешно подтверждена!',
                                'success'
                            )
                            showAllUsers();
                        }
                    });
                }
            });
        });


Getting data via post
if(isset($_POST['act_id'])){
    $id = $_POST['act_id'];
    $db->activePacient($id); 
     }


The function itself to update a record in the database
public function activePacient($id){
      $sql = "UPDATE пациент_авторизация SET проверка='1' WHERE пациент = :id";
      $stmt = $this->conn->prepare($sql);
      $stmt->execute(['id'=>$id]);
      return true;
    }


I can’t understand what the problem is, the identical code that works to delete the record is successful, and with a request to update the data, “undefined” is displayed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
P747, 2020-05-17
@kapelka001

What variable, "response.error"? Checked that the server answers, without errors?
They also forgot to add to the request:
dataType: 'json'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question