после нажатия кнопки сладкого оповещения вызов php файла - PullRequest
0 голосов
/ 11 февраля 2019

Я пытаюсь вызвать файл php после нажатия кнопки в сладком оповещении.Эта функция является подтверждением входа в учетную запись.Пример процесса - когда вы выходите из активной учетной записи, появляется всплывающее сообщение, которое было приятным предупреждением, и если вы нажмете кнопку ОК, то это должно было уничтожить сеанс пользователя.Может кто-то помочь мне с этим?

Вот мой код:

<a href="javascript:swal({title:'Logout', 
text:'Do you want to logout this Account?'
    , icon:'warning', 
    buttons: true, 
    dangerMode: true}).then((willOUT) => {
    if (willOUT) {
          url: 'page_logout.php', {
          icon: 'success',
        });
      }
    });" 
    class="nav-item dropdown-item">             
    Log out
</a>

см. Консоль

Ответы [ 3 ]

0 голосов
/ 11 февраля 2019

Это поможет вам.Это может привести вас к page_logout.php. Кроме того, в вашем коде swal есть ошибка, которую вы написали в

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <a href="#" id="a_id">Logout</p>
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("#a_id").click(function(){

                    swal({title:'Logout', 
                        text:'Do you want to logout this Account?', 
                        icon:'warning', 
                        buttons: true, 
                        dangerMode: true
                    })
                    .then((willOUT) => {
                            if (willOUT) {
                                  window.location.href = 'page_logout.php', {
                                  icon: 'success',
                                }
                              }
                    });

            });
        });
    </script>
</body>
</html>

, или если вы хотите показать сообщение на той же странице, где есть кнопка выхода,тогда вместо url в вашем вопросе сделайте ajax запрос к page_logout.php.Надеюсь, это поможет вам.

0 голосов
/ 12 февраля 2019

Вы можете использовать событие выхода из системы с функцией

<script src="https://unpkg.com/sweetalert2@7.8.2/dist/sweetalert2.all.js"></script>

<a onClick="logout()">Logout</a>
<script>
function logout(){
 swal({
  title: 'Logout',
  text: 'Do you want to logout this Account?',
  type: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#DD6B55',
  confirmButtonText: 'Yes!',
  cancelButtonText: 'No.'
}).then(() => {
  if (result.value) {
    // Call ajax page_logout.php File
  } else {
    // Close alert
  }
});

}
OR 
functio logout() {
swal({
    title: 'Are you sure?',
    text: "You won't be able to revert this!",
    type: 'warning',
    showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, delete it!'
  }).then(function() {
    swal(
      'Deleted!',
      'Your file has been deleted.',
      'success'
    )
  })
}
</script>
0 голосов
/ 11 февраля 2019

попробуй js:

<button type="button" onclick="logout('<?php echo $SESSION['user']['userId'] ?> ')" class="btn-danger">logout</button>
function logout(id) {
    swal({
        title: "Do you want to logout this Account?",
        type: "error",
        showCancelButton: true,
        confirmButtonClass: "btn-danger",
        confirmButtonText: "Yes!",
        cancelButtonText: "No",
        closeOnConfirm: true,
        closeOnCancel: true
    },
            function (isConfirm) {
                if (isConfirm) {
                    userLogout(id);
                }
            });
}

function userLogout(id) {
    $.post(base_url + "fileName/method_name", {id: id}, function (data) {
        if (data === "1") {
            }
         else if (data === "0") {
            swal("", "Error to logout user.", "warning");
        } else {
            swal("", data[0], "error");
        }
    });
}
...