title: How to pass variables from PHP to Javascript using Ajax calls
body: <p>I read <a href="https://stackoverflow.com/questions/15818870/how-to-pass-php-variable-value-to-javascript">this post</a> and assumed the technique in the answer would work with ajax calls. I have my ajax and php code below but it does not work.The client does not recognize the 'passed' variable. I do not know why nor how to remedy this. </p>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>var irrelevant = 'irrelevant';
  
     $('body').click(function(){
  
  
              $.ajax({
              type: 'POST',
              url: 'test.php',
              data: {mydata: irrelevant},    
              success: function(){
  
              console.log('worky');
  
              alert(myvar); // NOT worky!
  
                      }
  
              });
  
      });
  </code></pre>
  
  <p><strong>PHP File</strong></p>
  
  <pre><code>&lt;?php
  
  
  $thing = 10;
  
  
  ?&gt;
  
  
  &lt;script&gt;
  
  var myvar = "&lt;?php echo $thing; ?&gt;";
  
  &lt;/script&gt;
  </code></pre>