title: JavaScript variable undefined outside ajax
body: <p>im making a simple script so a piece of code can run in a loop.</p>
  
  <pre><code> var num_rows_php;
      var num_rows_sessions_php;
      var num_rows_session_php_teste;
  
      $.ajax({
      url: 'verify_num_rows.php',
      success: function(){
      num_rows_php = "&lt;?php echo $my_num_rows; ?&gt;";
      num_rows_session_php = "&lt;?php echo $_SESSION['transaction_count']; ?&gt;";
      num_rows_session_php_teste = "&lt;?php echo $_SESSION['teste_num']; ?&gt;";
      alert('num_rows_session' + num_rows_session_php);
      alert('num rows session php teste' + num_rows_session_php_teste);
      },
  
      });
  
      alert('teste fora do ajax' + num_rows_session_php_teste);
  </code></pre>
  
  <p>I only posted the relevant part here, where my problem is. So i create the variables outside the ajax function, so i can update them inside the ajax function. this piece of code is running every 5 seconds, so even if the ajax call isn't made first, the variables should update anytime. My problem is, when i do the <strong>Alerts</strong>inside the ajax function, the values are correct, but the alert outside the ajax function says the variable is undefined.
  <strong><code>alert('teste fora do ajax' + num_rows_session_php_teste);</code></strong> is undefined, even after the code runs like 10 times. Why is this ?</p>
  
  <p>EDIT : </p>
  
  <p>i tried this:</p>
  
  <pre><code>$.ajax({
              url: 'verify_num_rows.php',
              success: function(){
              num_rows_php = "&lt;?php echo $my_num_rows; ?&gt;";
              num_rows_session_php = "&lt;?php echo $_SESSION['transaction_count']; ?&gt;";
              num_rows_session_php_teste = "&lt;?php echo $_SESSION['teste_num']; ?&gt;";
              alert('num_rows_session' + num_rows_session_php);
              alert('num rows session php teste' + num_rows_session_php_teste);
              if (num_rows_session_php_teste != num_rows_session_php)
              {
                alert(num_rows_session_php_teste);
                  //   alert (num_rows_session_php);
                $('#tbody').load('table_body.php')
                $('#myfooter').load('myfooter.php')
                $('#my-list').load('mylist.php')
  
  
  
          }
          },
  
          });
  </code></pre>
  
  <p>everything inside ajax success function and the variable is undefined in the moment of the alert.</p>