The problem is with variables and return from function. This code help connect to mysql database and select distance between two cities. Variable ret_pomoc is the distance. 
Value in ret_pomoc I need to use in another function for example in another_fuction().
Here is code:
var ret_pomoc;
var vzdialenost;
function ajaxFunction(mesto_1,mesto_2){
            var ajaxRequest;  // The variable that makes Ajax possible!
            try{
               // Opera 8.0+, Firefox, Safari
               ajaxRequest = new XMLHttpRequest();
             }catch (e){
               // Internet Explorer Browsers
               try{
                  ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
               }catch (e) {
                  try{
                     ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                  }catch (e){
                     // Something went wrong
                     alert("Your browser broke!");
                     return false;
                  }
               }
             } 
     // Create a function that will receive data 
     // sent from the server and will update
     // div section in the same page.
     ajaxRequest.onreadystatechange = function(){
       if(ajaxRequest.readyState == 4){
          var ajaxDisplay = document.getElementById('mapa2');
          ajaxDisplay.value = ajaxRequest.responseText;
        ret_pomoc=ajaxDisplay.value; //HERE IS KEY VARIABLE
        console.log(ret_pomoc); // 1. Here it is OK show 91
       }
     } 
    console.log(ret_pomoc); // 2. Here it does not work show undefined and return does not work 
     // Now get the value from user and pass it to
     // server script.
            var z_mesta = mesto_1;
            var do_mesta = mesto_2;
            var queryString = "?z_mesta=" + z_mesta ;
            queryString +=  "&do_mesta=" + do_mesta;
            ajaxRequest.open("GET", "pristup.php" + 
                                  queryString, true);
            ajaxRequest.send(null); 
    } 
I need to use value from ret_pomoc in ahother function
function another_function(){
    vzdialenost=ajaxFunction('Bratislava','Nitra') + ajaxFunction('Poprad','Nitra') ;
    }
 
     
    