0

I don't know what is the best pratice but I have the index.html where I do:

<script src="getGames.php"></script>
<script src="../js/filters.js"></script>

In that php file I fetch the data from the db, I'd like to use that data in the .js file, how can I do it? what is the best pratice in this situation?

C-Gian
  • 62
  • 2
  • 19
  • 1
    Does this answer your question? [How do I pass variables and data from PHP to JavaScript?](https://stackoverflow.com/questions/23740548/how-do-i-pass-variables-and-data-from-php-to-javascript) – evolutionxbox Apr 25 '22 at 15:17
  • 1
    Remember, Javascript is client side, so relying on it to manage game variables may not be a great idea. (If that is what you plan on doing) – GrumpyCrouton Apr 25 '22 at 15:18
  • @GrumpyCrouton my purpose was to retrieve data from db in the php file and then use it in the javascript files – C-Gian Apr 25 '22 at 15:20
  • That's what AJAX is for. – Barmar Apr 25 '22 at 15:21
  • @C-Gian I understand, but that puts the values into the clients hand to handle. That means any client can theoretically do whatever they want. You (probably) want the server to actually handle changing data, so you should use AJAX. – GrumpyCrouton Apr 25 '22 at 15:22
  • I swear guys I'm trying all solutions I find but I can't make it work... Tried using ajax too – C-Gian Apr 25 '22 at 18:36

0 Answers0