JQuery: global vars don't work
Good morning,
i'm learning JavaScript and JQuery and i have a problem in defining vars.
In this code, on page load i load an external file using JQuery's Ajax methods, therefore i'd like to assign its value to a var to use later.
Unfortunately the syntax i'm using seems not work so i cannot, obviously, understand why.
Here the code:
- $(window).load(function() {
- $.get('http://localhost/_SandBox/JavaScript/Learn-JQuery/_SourceCodeFromPackt/Chapter%206/exercises-content.html', function(data) {
- tooltipsIndexes = data;
- });
- });
- $(document).ready(function() {
- console.log(tooltipsIndexes);
- ... OTHER CODE ...
- });
Trying to use console.log() it reports me:
Uncaught ReferenceError: tooltipsIndexes is not defined
What should i have to do to pass vars from $(window).load to $(document).ready ?
Thanks everyone for the help!