1

I've this function.

function ajaxtakesource4(callback){
    var ajaxRequest;  // The variable that makes Ajax possible!
    try{
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                alert("Your browser broke!");
                return false;
            }
        }
    }   
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange =function(){
        if(ajaxRequest.readyState == 4 &&ajaxRequest.status==200){
            var sourcetest = ajaxRequest.responseText;  
            callback(sourcetest);
        }
    }
    ajaxRequest.open("POST", "takesource4.php", true);
    ajaxRequest.send(null); 
}

Also:

var somous4;
function run() {
    ajaxtakesource4(function(sourcetest){   
        somous4=sourcetest;
    });
    alert(somous4);
}

and here I call the above the function:

<div id="run">
  <button id="button_run" class="button" onclick="run()">Run</button>
</div>

To make it clear i need to use the variable of somous4 in the function run not only to print it. My idea is to call a number of variables , with the same procedure. I need to store,use these variable by the some way(this is what i am searching) use all of them in the function and run the algorithm. I need something like to return these variables (i think it is not possible) or to use them as global variables in the function run. Thanks for your interest!

SoMous
  • 29
  • 4
  • Possible duplicate of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – David Apr 11 '16 at 13:44

0 Answers0