Page 1 of 1
[SOLVED]reading json content in JS which is defined in link
Posted: Thu Oct 13, 2011 9:12 am
by novice4eva
Hi friends,
I could really use your help on this. I have a json file with data like:
Code: Select all
//header set to "application/json"
{items : [{'10100':['huc6':10100, 'name':'St. John', 'historic_d':28, 'abslolute_loss':0, 'percent_loss':0.0000, 'fillColor':'#1ae8ff']},{......
And I want to read this content from javascript. I could have put things in js as var myJson = [the json content] but I would want to learn things via "link" way. Please do share your wisdom a bit
Regards,
Dee
Re: reading json content in JS which is defined in link tag
Posted: Thu Oct 13, 2011 3:18 pm
by pickle
What do you mean the "link" way? Do you mean to read this data from a file you access via AJAX?
Re: reading json content in JS which is defined in link tag
Posted: Thu Oct 20, 2011 12:19 pm
by novice4eva
Hi pickle,
Thanks for taking interest into this and I am really sorry for getting back to this - LATE(5 days to be exact!). I meant something like this:
Code: Select all
<html>
<head>
<link href="myJsonData.json" type="application/json" rel="exhibit/data" />
...
Libraries like simile exhibit read json data using this method. But I am not able to dissect how?
and myJsonData.json would have content as posted in my first thread.
Regards,
Dee
Re: reading json content in JS which is defined in link tag
Posted: Thu Oct 20, 2011 12:33 pm
by pickle
So you just want to be able to access the information in myJsonData.json & work with it in Javascript? I honestly don't know why you would put it in a <link> tag. That wouldn't bring the JSON data into your Javascript environment. You'd have to access the tag with Javascript & make another call to the URL specified by the "href" attribute, resulting in the data being downloaded twice.
Putting it in a <script> tag would make way more sense.
[SOLVED]Re: reading json content in JS which is defined in l
Posted: Thu Oct 20, 2011 12:51 pm
by novice4eva
Hummm now that's interesting..shoot you are right they are making an ajax call because I always saw a get request being made in the firebug console for the json file BUT damn, it never crossed my mind. Pickle thanks a lot - I think I get it how they(simile exhibit) are doing it now. I thought they were somehow loading the content via the link - and felt like wow that's neat. Thank you so much again. I wish I had a smiley to show you my appreciation for "bringing me into light"

Re: reading json content in JS which is defined in link tag
Posted: Thu Oct 20, 2011 1:14 pm
by pickle
Heh - glad to help.
If you are putting [SOLVED] in the subject title, edit your original post - changing you most recent post doesn't update the title shown in the forum.