I have this .json file and I want to load it in a global variable that I can access from all web using AJAX, JavaScript. How can I do it? I want to access the variable by the index, for example my_var[1].img. I read a lot of posts but I didn't find the solution.
myData.json
{
"data": [
{ "img": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHQ5Sf2Cffo0QdRtFw0t8zdk90FWgywc1kDKAuOV874zYO_0pC", "other": "Ra.One" },
{ "img": "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQkVg9n2UbPTeiPNGUOw2SqdAzJsZzuHrkYw78sjaMMCcTWcuFjUtT3NZ8", "other": "3 Idiots" },
{ "img": "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQ0Wam0d96ASpEHDFfskGTBdILKlDpXAKzELFdfdKmkoye5JmrF9qS1u1qtZw", "other": "Chaalis Chauraasi (4084)" },
{ "img": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSAf7q-m96JL88_W8EATmVlwCfOKb5dw1keyDSO6PWwzaSVtqGyix2lvE", "other": "Gangs Of Wasseypur" }
]}
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MyWeb</title>
<script type="text/javascript" src="myData.json"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<script>
var my_json;
$.getJSON("myData.json", function(json) {
my_json = json;
});
</script>
</body>
</html>