JS global variable is not updating inside ajax : <p>This is my code:</p>

<p>I based the window variable from <a href="https://stackoverflow.com/questions/5786851/define-global-variable-in-a-javascript-function">here</a></p>

<pre><code>&lt;script&gt;
                $(window).on("load", function() {

                   function myForeverFunc(){
                       window.global_time = "3";
                       $.ajax({
                           url: "index.php?action=showReminder",
                           cache: false,
                           success: function(data){
                               if(data &amp;&amp; data.charAt(0) === "1"){

                                    window.global_time = "1";
                               }else{
                                   console.log("test");
                                   window.global_time = "2";
                                }
                           }
                        });
                        console.log(window.global_time);
                    }
                   setInterval(myForeverFunc, 60*1000);
               });
           &lt;/script&gt;
</code></pre>

<p>This just displays "3" where it should have been updated to "2" in the else part of the ajax function.</p>
