Change of alert by sweet alert

0

      if($resultado_pendientes>=1){

        echo "alert(\"Usted posee 1 solicitud cerrada parcialmente por el departamento de sistemas, valide y cierrela antes de crear otra nueva.\");
              document.location=(\"./listTicketUnrevised.php?active=0\");";
      }

    ?>

Good, I need help with this code that I have, which generates a current alert and I want to change it for the sweet alert.

The problem is that it always gives me errors. I want to use the warning of that library but I do not know how to implement it ...

doubt 1 I do not understand why the \ inside the alert are used but I am seeing that without that the warning message is not printed. doubt 2 when changing what is inside the echo quotes I get an error Parse error: syntax error, unexpected '=' Try putting the document location in the echo but it still does not work.

    
asked by Juan Ortiz 09.03.2018 в 13:25
source

2 answers

0

that if I had done it, what I had not done was to separate the php from javascript

<script>
        <?php


          if($resultado_pendientes>=1){
//aqui ira el sweet alert y aqui cerre el php , cosa habia hecho despues del sweet alert 
?>
        swal({
  title: 'Tiene 1 ticket pendiente por cerrar',
  html: 'Cierrelos para poder crear uno nuevo ',
  type: 'warning',
  confirmButtonText: 'Got it!'
}).then(function () {
  window.location.href = "tickets-sin-revisar-1";
}, function (dismiss) {
  // dismiss can be 'cancel', 'overlay',
  // 'close', and 'timer'
  if (dismiss === 'cancel') {
    window.location.href = "tickets-sin-revisar-1";
  }
});

          <?php    
//aqui lo vuelvo a abrir para cerrar el if continuando con mi js   
//este codigo lo copie de la web de aca , yo le hice la modificacion  al darme //cuenta y funciono , me redirije a la pagina que quiero , ya le agrego el //tiempo de redireccionamiento usando la version 2del sweet alert.
//posteo el codigo para que la gente se ayude si tiene este problema
// saludos 
          }
        ?>
    });

  </script>
    
answered by 09.03.2018 / 14:45
source
2

To the answer of how to implement a Sweetalert2 , you just have to add the necessary libraries, jQuery and those of sweetalert2 and then modify the syntax of alert .

Here I leave you a working sample. and here your website with more information about configurable parameters

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.11.0/sweetalert2.css"/>
   <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.11.0/sweetalert2.js"></script>
</head>
<body>
<script>
function alerta(){
 swal({
   title: "¡ERROR!",
   text: "Esto es un mensaje de error",
   type: "error",
 });
}
     alerta();                   
</script>
</body>
</html>

If what you want is to show the alert from php this can help you, I can see how I combine double and single quotes:

<?php echo "<script> swal({
   title: '¡ERROR!',
   text: 'Esto es un mensaje de error',
   type: 'error',
 });</script>";
?>

In this answer you will find more information about the quotes.

    
answered by 09.03.2018 в 13:48