title: how to send mouse coordinates continously to flask during user interaction on a web app using fetch-API?
body: <p>I am trying to send a user's mouse position, while she is moving the cursor on the webpage. So the below code, for some reason doesn't send the mouse data continuously to flask, but instead  waits till the end of the session and sends all of it after the user has clicked on cancel/save button. I don't have any listeners on these buttons. So I don't understand why the code is  waiting till the end to send the data. What am I  missing here?</p>
  
  <p>So this is what my app.py looks like:</p>
  
  <pre><code>import json
  
  from flask import Flask, url_for, render_template, request, redirect, make_response, jsonify
  
  app = Flask(__name__,static_folder='static',
              template_folder='templates')
  
  
  @app.route('/')
  def index():
      return render_template('Introduction1.html')
  
  @app.route('/test', methods=['GET','POST'])
  def test():
      req=request.get_json()
      print (req)
      print()
      return render_template("Index.html")
  
  @app.route('/danke')
  def danke():
      return render_template("Thankyou.html")
  
  if __name__ == '__main__':
      app.run()
  
  </code></pre>
  
  <p>This is the mouselistener in my .js file including the fetch API code:</p>
  
  <pre><code>function showMovementCoords(event) {
  
       cdata = event.clientX.toString() + "_" + event.clientY.toString()
      fetch(`${window.origin}/test`, {
              method: "POST",
              credentials: "include",
              body: JSON.stringify(cdata),
              cache: "no-cache",
              headers:  new Headers({
                  "content-type": "application/json"
              })
          })
  }
  
  </code></pre>
  
  <p>Here  my save/cancel buttons, just in case:</p>
  
  <pre><code>&lt;div class="actions"&gt; &lt;a class="btn btn-default btn-cancel" href="{{ url_for( 'Thankyou' ) }}" id ="cancel"&gt;&lt;i class="fa fa-arrow-left"&gt;&lt;/i&gt; Cancel&lt;/a&gt;
                         &lt;a class="btn btn-default btn-save"   href="{{ url_for( 'Thankyou' ) }}" id ="save"&gt;&lt;i class="fa fa-check"&gt;&lt;/i&gt; Save&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>quick recap of what I  want to achieve: user opens the page, does stuff, every time she moves the cursor the new mouse coordinate is sent to flask and I expect flask to print this. user clicks on save/cancel. "Thankyou" page opens.</p>