Calling Javascript in PHP

Asked

Viewed 1,043 times

0

I’m starting in PHP and I’m a technician in VB.NET and MYSQL. The only language I don’t have is Javascript and PHP.

I have a question where I need to call a notification in index.php.

This is the script Notify and I’m trying to make it appear. My file is like this:

Código do index.php

And I want to call this notify: inserir a descrição da imagem aqui

but I return this error: inserir a descrição da imagem aqui

Can anyone explain to me how I add the script? Regardless of which one, I just need to understand how to make the call. Thank you

  • Java is not Javascript. It’s two different things.

  • Yes, so I’m talking about Javascript.

1 answer

2


You’re using Javascript code inside a PHP block (<?php ?>). You must put the code inside the script tag:

<script>
  // código aqui
</script>

But it is also necessary that the plugin file be loaded before the code:

<script src="/not/bootstrap-notify.min.js"></script>
<script>
  // código aqui
</script>

You will also need to load jQuery before all libraries. Example:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="/not/bootstrap-notify.min.js"></script>
<script>
  // código aqui
</script>
  • I was already typing that I was not loading, but with the jquery that you asked me to add worked. Valew ! Gave right. Just a question, if I want to call this notification after clicking a button I call it as?

  • it would be something like that: $("button").click(function(){ $.notify({ opções aqui }) });... where "button" can be a class, id etc.. to identify the button clicked

  • It worked, Sam, I got the call. Every time I run the script I have to call the <script src="/not/bootstrap-notify.min.js" ></script> tag? Is there no way I can define this tag in a place on the page that is always accessible? Because the code would be cleaner...

  • You just put it on <script src="/not/bootstrap-notify.min.js"></script> only once on the page to load the plugin.

  • always above the first place I will use right?

  • Not necessarily. You can organize the scripts that will be loaded in <head>, for example

Show 1 more comment

Browser other questions tagged

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