I have a file.json
with contents:
{
"a":{"var1":"Sábado"},
"b":{"var2":"Domingo"}
}
Having in mind that I cannot edit file.js
, I need to figure out a way to load the json contained in that file into a variable mj
, so that alert(mj["a"].var1)
shows me the message Sábado
.
UPDATE: Is this possible to accomplish without using JQuery, Prototype, or any other js library?
This is plain js,(with no use of eval) and should even work cross domain:
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "file.js"; /*url of your js/jsonp file */
var head = document.getElementsByTagName('head')[0];
head.insertBefore(script, head.firstChild);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With