There are actually several approaches to do this. Some require more overhead than others, and some are considered better than others.
In no particular order:
- Use AJAX to get the data you need from the server.
- Echo the data into the page somewhere, and use JavaScript to get the information from the DOM.
- Echo the data directly to JavaScript.
In this post, we'll examine each of the above methods, and see the pros and cons of each, as well as how to implement them.