title: Simple fetch GET request in javascript to a flask server
body: <p>I'm trying to display some json data from a flask server to my html page but I have a <code>TypeError: NetworkError when attempting to fetch resource.</code> with a <code>Promise { &lt;state&gt;: "rejected" }</code>.</p>
  
  <p>server.py</p>
  
  <pre class="lang-py prettyprint-override"><code>from flask import Flask, request, jsonify
  
  app = Flask(__name__)
  
  
  @app.route('/hello', methods=['GET'])
  def hello():
      jsonResp = {'jack': 4098, 'sape': 4139}
      print(jsonify(jsonResp))
      return jsonify(jsonResp)
  
  if __name__ == '__main__':
      app.run(host='localhost', port=8989)
  </code></pre>
  
  <p>script.js</p>
  
  <pre><code>function getHello() {
      const url = 'http://localhost:8989/hello'
      const response = fetch(url)
      console.log(response);
      document.getElementById("demo").innerHTML = response;
  }
  
  </code></pre>
  
  <p>index.html</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="ie=edge"&gt;
      &lt;title&gt;Document&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;button onclick="getHello()"&gt;click&lt;/button&gt;
      &lt;label id="demo"&gt;&lt;/label&gt;
  
      &lt;script src="script.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I also have a <code>[object Promise]</code> in the label section when I click on the button.</p>
  
  <p>I did the simplest code possible but it doesn't work.</p>