1

I generate a json file using python, now i can read it via javascript, but what i want is that to assign value in the json file in order to use them in other functions. the fist console.log works fine, the result of the second is "undefined" how can i call "IndexCooX" outside the function?

<script>
    window.onload = function () 
    {
        function loadJson() 
        {                
            $(document).ready(function()
            {
                $.getJSON('right_json_file.json', function(json) 
                {
                    IndexCooX = json.right.coordinates.Index[0];
                    IndexCooY = json.right.coordinates.Index[1];
                    console.log("X1 "+IndexCooX+" Y1 "+IndexCooY);

                    });
            });

        }
            loadJson();
            console.log("from outside: "+loadJson.IndexCooX);
    }
</script> 
y0un35
  • 9
  • 3

0 Answers0