I have a php file that echos JSON encoded arrays, the contents of which are pulled from a remote database.
I want to be able to pass this data from the PHP file to a Javascript file linked to a running HTML file displayed in the browser.
What are the best practises for passing data, particularly in JSON format fromPHP to Javascript...
-
Look up this popular thing called "Ajax".Peter C– Peter C2011年08月07日 02:30:09 +00:00Commented Aug 7, 2011 at 2:30
-
Can you clarify? Is the PHP script with the arrays generating the HTML file, which has the reference to the JS script? Or is the JS script querying a separate PHP script?bjudson– bjudson2011年08月07日 02:32:19 +00:00Commented Aug 7, 2011 at 2:32
-
the latter. the html file will trigger a js function that queries the phpuser559142– user5591422011年08月07日 02:40:54 +00:00Commented Aug 7, 2011 at 2:40
1 Answer 1
The jQuery Javascript library provides a bunch of great ways for handling Ajax. JSON is a wonderful format for client/server communication, even as-is. XML is also good.
If you are talking about long polling, you may also want to look into COMET