How can I get the content of url.json, and cast the json to a variable. The content of url.json is pure json format. Thanx
-
Do you try to access a JSONP service?Fox32– Fox322012-02-09 10:19:01 +00:00Commented Feb 9, 2012 at 10:19
-
4You can't. It will be evaluated as JavaScript and just vanish in the void.Felix Kling– Felix Kling2012-02-09 10:21:41 +00:00Commented Feb 9, 2012 at 10:21
-
JSON is not a scripting language, so I guess it's not possible this way.pimvdb– pimvdb2012-02-09 10:26:19 +00:00Commented Feb 9, 2012 at 10:26
-
same-orgin, or cross domain?Joshua Wooward– Joshua Wooward2013-02-08 22:48:37 +00:00Commented Feb 8, 2013 at 22:48
Add a comment
|
3 Answers
Are you aware of the jquery getJSON api? You can use this to download json from an url. Not sure if you can embed some json directly in a script tag, though.
Comments
You need to read in the contents from the url using AJAX and then put that into your variable or use the data as soon as you successfully get the data.
See here for non jQuery vanilla javascript methods: reading server file with javascript and also Consuming JSON data without jQuery (sans getJSON)