1

I am working on a mini project on PHP. I'm using a div tag (with id="words") for displaying the words to be typed. For time being I've used javascript for initializing words with a particular string of text, using a variable str.
I've saved the code for initialization in script.js along with all the other javascript code needed for the site and have linked it to the main PHP page.
Now if I want to fetch the string of text from the database, I'll have to use PHP. So how do I use PHP to fetch the data and store it in the str variable for the initialization function to do it's work.

PS:
str variable is declared in the script.js file.

rdias002
  • 214
  • 2
  • 9
  • Read something about ajax. – Martin Heralecký Dec 25 '17 at 16:35
  • 1
    This is a very simple question which can be solved with Google. If you are having specific problems with some code that isn't working, come back and ask, otherwise I'd suggest a search. – webnoob Dec 25 '17 at 16:36
  • Well if it's a one-time loading into a script file of a PHP variable, AJAX is not necessary. @MartinHeralecký Read something JSON – dGRAMOP Dec 25 '17 at 16:37
  • Dynamic javascript variables. Hidden form elements printed by PHP. Ajax. – Dharmang Dec 25 '17 at 16:37
  • @Dharmang he wants the variables to be dynamic? – dGRAMOP Dec 25 '17 at 16:38
  • Yaa JSON is good option then. – Dharmang Dec 25 '17 at 16:40
  • This sounds more like a duplicate of https://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript –  Dec 25 '17 at 16:42
  • Thank you very much for your precious comments and time. This was my first question on stackoverflow. I also am a newbie in php and javascript. Will learn ajax and json now... :) – rdias002 Dec 25 '17 at 17:09

0 Answers0