Set value of a scoped variable in callback / closure
<p>I have a very large JS script with many functions, callbacks and so on... one of my first actions is to obtain a value from an Ajax call. This value I then set to a global variable defined at the start of my script so I can reference the value again and again... the value with determine the user language for instance.</p>

<pre><code>// define my global var at the top of my script..
var globalOpCo = "";

// I then try to give this a value in the next function I call...
$.ajax({
        url:"getURL",
        type:"POST",
        dataType:"json",
        success:function(data){
            if(data === null){
            // do something...  
            }else{
            // set the current language...
                globalOpCo = data.Opco.toLowerCase();
                console.log(globalOpCo); // this is the value I want it to be from data.Opco.toLowerCase() 
                // now do something.... 
            }
        },
        error:function(xhr, ajaxOptions, thrownError){
            console.log(xhr.status);
            console.log(xhr.statusText);
            console.log(thrownError);
        }
    });
</code></pre>

<p>Now later in my script I wish to pass the <code>globalOpCo</code> to another function like so...</p>

<pre><code> $("#aButton").on("click", function(){
        anotherFunction(globalOpCo); // I want to pass the globalOpCo as an arguement but its value isn't get updated above?
    });
</code></pre>

<p>however the value of <code>globalOpCo</code> is an empty string! The #aButton cannot be clicked before or until the ajax call above is run. Can someone help?</p>
