echo with sweetalert not working

I am trying to echo a alert/notification box. This one is working fine –

echo '<script language="javascript">';
echo 'alert("Record successfully added in database")';
echo '</script>';

But I want to give timing for disappear the box after 2 seconds. I have no idea how to do it. I found through sweetalert it is possible. So I did like this

echo '<script src="sweetalert/lib/sweet-alert.min.js">';
echo '<link rel="stylesheet" type="text/css" href="sweetalert/lib/sweet-alert.css">';
echo 'swal({   title: "Record added successfully!",   
               text: "I will close  in 2 seconds.",   
                timer: 2000 
echo '</script>';
Any help will be greatly appreciated.
Bronze Asked on January 12, 2018 in PHP.
Add Comment
1 Answer(s)
 echo '<script type="text/javascript">';
 echo 'setTimeout(function () { swal("WOW!","Message!","success");';
 echo '}, 1000);</script>';

I hope this solution is useful for you.

Starter Answered on January 12, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.