Send php variable to javascript file

Re: Send php variable to javascript file

by Mark Johnson -
Number of replies: 0
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

As the error suggests, AJAX or data attributes are good ways to do this.

For data attributes, you'd pass the records to your template and have them output in data attributes of corresponding HTML elements, then have Javascript read the data via the DOM and do whatever you're trying to do with those elements.

For AJAX, you'd write a new web service function that returns the records, then have your Javascript call that function via AJAX when the page loads to get the data. If you're dealing with a large volume of data, this is probably the easier option.