skip to Main Content

I am trying to display an alert message after the record is inserted in the datbase and normal js alert is working fine the code for this is

echo '<script>';
echo 'alert(" Your request has been successfully filled and your Letter No isn'.$Dep.'/'.$fy.'/ "+"'.$id.'.nKindly submit the original copy of this letter to CRDS.")';
echo '</script>';
echo "<script>window.location.href='dashboard.php'</script>";
exit;

But when I am using sweet alert function instead of normal js function it does not display any message.What is wrong in my code> I have included sweet alert library in my code.My code is

echo '<script>';
    echo 'swal(" Your request has been successfully filled and your Letter No isn'.$Dep.'/'.$fy.'/ "+"'.$id.'.nKindly submit the original copy of this letter to CRDS.")';
    echo '</script>';
    echo "<script>window.location.href='dashboard.php'</script>";
    exit;

3

Answers


  1. most likely the swal function is wrong, look at the swal documentation and here is an example of how to use it, maybe you are missing the fire.

    Swal.fire(
      'Good job!',
      'You clicked the button!',
      'success'
    )
    

    that on that side of the alert, however if we look at the topic more in depth, in the last line you are changing the url with the window.location.href, then it would be good to comment or implement it differently because there you are redirecting it to another page and the alert will not be displayed.

    Login or Signup to reply.
  2. using SweetAlert you can just simply use the:

    echo 'swal("Some'.$variable.'text!", "You clicked the button!", "success")';

    but in SweetAlert2 you can just simply use:

    echo ;Swal.fire(
      'Some'.$variable.'text!',
      'You clicked the button!',
      'success'
    )';
    
    
    You can try this one
        `echo "<script>
                    Swal.fire({
                            title: 'Successfully save!',
                            html: `Your request has been successfully filled and your Letter No isn 
                             ${$Dep}/${$fy}/${$id}nKindly submit the original copy of this letter to 
                              CRDS..`,
                             timer: 2000,
                             timerProgressBar: true,
                            }).then((result) => {
                          window.location.href='dashboard.php'
                   })
                 </script>"
                 `
    
    
    Login or Signup to reply.
  3. In your headings,

    Add,

    <head>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    </head>
    

    Then,

    echo '
        <script type="text/javascript">
            $(document).ready(function(){
                swal({
                    title: "Successfully save!",
                    html: "Your request has been successfully filled...",
                    timer: 2000,
                    timerProgressBar: true,
                }).then(function() {
                    window.location = "( Your link here. )";
                });
            });
        </script>
    ';
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search