Global variables in Javascript not updating
<p>I have spent the last 30 mins figuring this out. </p>

<p>Let's assume the following case: </p>

<pre><code>&lt;script&gt;
    var x = 0 ; //global variable
    function compute() {
        x = x+1; 
    }
&lt;/script&gt;
</code></pre>

<p>Should the value of x be incremented so I can access it into a function later on? </p>

<p>I have the following codes: </p>

<pre><code>var id1 = 0;
var id2 = 0; 
$.ajax({
    url: "http://localhost/twee/chat/comment",
    type: 'POST',
    data: form_data,
    success: function(data) {
        var data1 = parseInt(data);
        id1 = id2 = data1; 
    }
});
</code></pre>

<p>I want to be able to access the values of id1 and id2 (updated since i declared them as 0) in a later function. </p>

<p>However, the value is staying zero and data1 is retrieved just fine. </p>
