Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Providing perl array data to javascript code

by Eily (Monsignor)
on Nov 19, 2015 at 09:54 UTC ( [id://1148105]=note: print w/replies, xml ) Need Help??


in reply to Providing perl array data to javascript code

Your a) and b) solutions are not exclusive. Since the JS in JSON stands for JavaScript, using JSON to transmit data just means writing it in a JavaScript format. So if you embed that JSON output in the code somewhere, that's your solution one.

Outputing JSON with perl is ridiculously easy with the JSON module: use JSON; my $json = encode_json $nested_arrays_and_hashes; (or to_json, both are not stricly equivalent, but you can do a bit of documentation reading :) ). Once your data is in an easy to use format, you have to decide weither you want it to be statically embeded in the pages' code, or if it should be fetched asynchronously

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1148105]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-24 07:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found