title: Triggering Python script using AJAX Javascript request on local server using vanilla JS
body: <p>I have a localhost environment running using Python's SimpleHTTPServer, serving on port 8080.</p>
  
  <p>My project consists of an HTML file, a python script, and a Javascript (vanilla) script.</p>
  
  <p>The method I wish to employ is as follows:</p>
  
  <ul>
  <li>Click button in HTML</li>
  <li>Button fires Javascript AJAX request</li>
  <li>AJAX request runs Python script</li>
  <li>Python script produces JSON and returns it to Javascript</li>
  </ul>
  
  <p>My JS is the following:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>var json;
  
  function trigger() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
      if (this.readyState == 4 &amp;&amp; this.status == 200) {
          json = xhttp.responseText;
          console.log(json);
      }
    };
    xhttp.open("GET", "./request.py", true);
    xhttp.send();
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Right now rather than seeing the output of a Python script I'm just seeing the content (as text) of the Python file.</p>
  
  <p>I'm not sure of the correct AJAX call to RUN the .py script rather than just reading it and returning the contents.</p>
  
  <p>Any help would be greatly appreciated!</p>