Alert works and sweetalert does not

Asked

Viewed 1,821 times

1

I’m trying to use sweetalert to give an alert of "Submitted".

if($rstSql["cod_erro"] == 0)
{
    echo '<script> swal("Good job!", "You clicked the button!", "success"); <script>';
}
else
{
   echo '<script>alert("message2");</script>';   
}

Apparently the standard alert works, while the SWAL doesn’t. I tested on another page and called normally, libraries are being called on:

<script src="swap/sweet-alert.js"></script> 
<link rel="stylesheet" type="text/css" href="swap/sweet-alert.css">

When I debug Chrome I have the following message:

Uncaught Typeerror: Cannot read Property "prototype'of Undefined>

  • Which @Felipe line is this error (in the console speaks the line). Could post an example of the problem in jsfiddle?

  • In the code, the error appears only in the line I call swal, which I have already posted above. However, I get error in some lines of the Sweetalert library: Uncaught Typeerror? Cannot call method 'appendchild' of null. The funny thing is that I use the same library in a clean file and this one works.

  • You put <script src="swap/sweet-alert.js"></script> inside <head> and if($rstSql["cod_erro"] == 0)&#xA;{&#xA; echo '<script> swal("Good job!", "You clicked the button!", "success"); <script>';&#xA;}&#xA;else&#xA;{&#xA; echo '<script>alert("message2");</script>'; &#xA;} inside <body>???

1 answer

2

Good afternoon! I joined the Sweetalert website (http://t4t5.github.io/sweetalert/), I opened the browser console and typed the same line you commented on above, I mean:

swal("Good job!", "You clicked the button!", "success");

I did it to know if it was not a mistake of some parameter that you had passed or something, but it worked correctly! So apparently Sweetalert’s Javascript is ok!

I went back to read your post, and I noticed that you give an echo, but you’re not closing the tag <script>.

Please try to replace this line:

echo '<script> swal("Good job!", "You clicked the button!", "success"); <script>';

For that reason:

echo '<script> swal("Good job!", "You clicked the button!", "success"); </script>';

And please give us the answer if it worked.

  • I made the change and I didn’t get any results.

  • Same error keeps appearing on Chrome console?

  • Yes, the same mistake. I believe there may be some problem with the layout I’m using, which I’ve already gotten ready with several libraries. I think that because once I do this without the layout, Alert works normally.

  • Shall we try something? Change your <script> tag where you call Sweetalert Javascript to this: <script type="text/javascript" src="swap/Sweet-Alert.js"></script>. And please let me know if it worked.

  • Nikofoxxx, it didn’t work because I use Notepad++ and it recognizes <script> as javascript by definition.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.