By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,060 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,060 IT Pros & Developers. It's quick & easy.

How to handle data produced by a PHP script on a web page?

P: 1
Let's start with saying I'm a PHP . My goal is to process some data created by a PHP script, using JS.

Imagine my PHP script produces an array [1, 3, 7, 5]. I would like to use this array for making a chart. But somehow I don't understand how to make this data accessible for a JS script. Should I store it in a variable? If yes, how can I access it? Thanks a lot.
Dec 11 '19 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,389
depends how you implement your code. PHP can be called via an (XML)HttpRequest for example and return the data in JSON-format (typical way these days) or you can write plain text like:

Expand|Select|Wrap|Line Numbers
  1. var arr = ['your array elements'];
into a script-node of the html-page. JavaScript is executed in the browser - so the browser would take care of the parsing at the time the page is loaded and you would have an accessible variable for JavaScript (call this the 'legacy' way of doing such - but it can have some advantages in some cases to go this route).

Note: for PHP the JavaScript-code is just plain text - while as soon this text hits the browser - it becomes executable
Dec 11 '19 #2

Post your reply

Sign in to post your reply or Sign up for a free account.