title: How do I ensure a PHP variable is available in index.php after being changed in a second php file (via a jQuery load())?
body: <p>In my <code>index.php</code> I have the following jQuery code for responding to clicking an image:</p>
  <pre><code>&lt;script&gt;
      $(document).on('click',&quot;.i-give-up&quot;, function() {
          $(&quot;#take-a-guess&quot;).load(&quot;get_snippet.php&quot;);
  
          [...snip...]
  
          generate_HSK2_circle(&lt;?php echo $answer_data[&quot;HSK2level&quot;]; ?&gt;);
      });
  &lt;/script&gt;
  </code></pre>
  <p>When I click the image, it loads <code>get_snippet.php</code> which performs and processes a MySQL query.  Moreover, if I add</p>
  <pre><code>echo &quot;&lt;script&gt;console.log('get_snippet[new] HSK2 level: &quot; . $answer_data[&quot;HSK2level&quot;] . &quot;' );&lt;/script&gt;&quot;;
  </code></pre>
  <p>to the end of <code>get_snippet.php</code>, I can see the correct variable for <code>$answer_data[&quot;HSK2level&quot;]</code> in <code>get_snippet.php</code>.</p>
  <p>The problem is that the variable <code>$answer_data[&quot;HSK2level&quot;]</code> in <code>index.php</code> does not change as a result of loading <code>get_snippet.php</code>.</p>
  <p><strong>Question</strong>: How do I ensure a PHP variable is available in index.php after being changed in a second php file (via a jQuery load())?</p>