Storing Ajax Request Results into a Javascript Var
<p>I am trying to store the results of the return ajax call as: var yValue that is usable in javascript, but the results returning for yValue is always 0. </p>

<pre><code>&lt;head&gt;    
$.ajax({
      url: 'test2.php',
      success: function(data) {
          var yValue= data; // data contains value 1; 
      }
    }); 

    alert (yValue); 
&lt;/head&gt;
</code></pre>

<p>The results returned is always zero or null, and when i try to check for the value of data using an alert box, it is always 1. </p>

<p>Even when i used data as the result to store into my array"dynamicdata" that i have created, it will return a value of 0 or NULL: </p>

<pre><code>var globalData = null;
$.ajax({
    url: 'test2.php',
    async: false,
    success: function(data) {
        globalData = data;
    }
});

            var j=j+1;

            var CurrentDate1 = new Date((new Date()).getTime())
            var hours=CurrentDate1.getHours()
            var minutes=CurrentDate1.getMinutes()
            var seconds=CurrentDate1.getSeconds()
            if (minutes&lt;=9) minutes="0"+minutes;
            if (seconds&lt;=9) seconds="0"+seconds;
            var timer=hours+":"+minutes+":"+seconds+"";


            // remove the first element
            dynamicdata.splice(0, 1);
            // add a new elemez
            dynamicdata.push([timer, globalData]);
</code></pre>

<p>Anyone can help?</p>
