I want to change my global variable "nyText" to another value that I got from an AJAX request. I made a callback function, and I am able to successfully alert "nyText" from inside it. As soon as I move the alert(nyText) outside of the callback function, the value is undefined.
AJAX:
    $.ajax({
  type: 'GET',
  url: 'http://JUST_A_LINK_IGNORE_THIS',
  success: 
  function informationData(data) {
    $.each(JSON.parse(data), function(imgName,order){
        var path_image = order[0].path_image;
        imgName = order[0].path_image;
        dataReceiver(imgName);  
    });
  }
});
Other code:
 var nyText;
function dataReceiver(imgName){
nyText = imgName;
//alert(nyText);  would have worked
}
dataReceiver();
alert(nyText); //will not work
Thank you!
