title: Extracting Data from Ajax Request in Python
body: <p>I am unsure how to extract data from an Ajax request from my Javascript code in a python application in Flask. My Ajax request does not use jQuery.</p>
  
  <p>I have tried using <code>request.form.get()</code> and <code>request.get_json()</code> in my Python code but both produce a <code>None</code> value.</p>
  
  <pre><code>@app.route("/", methods=["GET", "POST"])
  def index():
      if not request.get_json() == None: 
          print(request.get_json())
          name = request.get_json()
          session["name"] = name.user
      return render_template("index.html", channels=channels)
  </code></pre>
  
  <p>In my Javascript code I perform a simple Ajax request:</p>
  
  <pre><code>    if(localStorage.getItem("user")) {
          document.querySelector("#logout").addEventListener("click", () =&gt; {
              localStorage.removeItem("user");
          })
  
          const request = new XMLHttpRequest();
          request.open("POST", "/")
          user = JSON.stringify(localStorage.getItem("user"))
          request.send(user)
      }
  </code></pre>