title: Return python script data after Ajax call
body: <p>i'm running a webserver using Node.js. I have 3 files: <code>index.html, client.js and temp-meter.py</code>.</p>
  <p><strong>PROBLEM :</strong> When clicking on the html button, my data isn't returned because i can't see it in my browser console. So i just need to get the result of my phython script and send it back to the 'client.js' file! This does not work.</p>
  <p><strong>index.html</strong></p>
  <p>This file has a simple button with an 'onclick-event' that calls a <code>getData()</code> function.</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
      &lt;title&gt;Python Project&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;button class=&quot;btn&quot; onclick=&quot;getData();&quot;&gt;Get Data&lt;/button&gt;
  
      &lt;script src=&quot;https://code.jquery.com/jquery-3.5.1.js&quot;
          integrity=&quot;sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=&quot; crossorigin=&quot;anonymous&quot;&gt;    &lt;/script&gt;
      &lt;script src=&quot;./client.js&quot;&gt;&lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  <p><strong>client.js</strong></p>
  <p>The function <code>getData()</code> makes an ajax GET request and executes the python script:</p>
  <pre><code>function getData() {
  $.ajax({
      method: 'GET',
      url: 'temp-meter.py',
      dataType: 'json',
  
      success: function (data) {
          const res = JSON.parse(data);
          console.log(res);
      }
  });
  }
  </code></pre>
  <p><strong>temp-meter.py</strong></p>
  <pre><code>import random
  import json
  
  def getData():
      arr = []
      i = 0
  
      for i in range(10):
          n = random.randint(-10,35)
          arr.append(n)
  
      som = 0
  
      for item in arr:
          som += item
  
      avg = som / 10
      avg = json.dumps(avg) #encode the data with json
  
      return avg #this avg needs to be returned to JS
  </code></pre>
  <p>When i simply <code>alert(data)</code> after the ajax request (success), then it alerts me the whole python script... (I just want the avg result).</p>