title: Showing POST http://localhost:81/test 404 (Not Found) when using JQuery,ajax
body: <p>I am trying to pass javascript variables to python as a directory using the JQuery.ajax and flask application.</p>
  <p><strong>index.html</strong></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>&lt;body&gt;
  &lt;label for="fname"&gt;First name:&lt;/label&gt; &lt;input type="text" id="fname" name="fname"&gt;
  &lt;label for="lname"&gt;Last name:&lt;/label&gt;&lt;input type="text" id="lname" name="lname"&gt;
  &lt;button type="submit" onclick='myfunction();'&gt;Click Here to pass your data&lt;/button&gt;
  &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      function myfunction() {
          const firstname = document.getElementById("fname").value;
          const lastname = document.getElementById("lname").value;
  
          const dict_values = {firstname, lastname} 
          const s = JSON.stringify(dict_values); 
          console.log(s); 
          $.ajax({
              url:"/test",
              type:"POST",
              contentType: "application/json",
              data: JSON.stringify(s)});
  }
  &lt;/script&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  <p><strong>app.py</strong></p>
  <pre><code>import json
  from flask import request
  from flask import Flask, render_template
  app = Flask(__name__)
  @app.route('/')
  def index():
      return render_template('index.html')
  @app.route('/test', methods=['POST'])
  def test():
      output = request.get_json()
      print(output)
      print(type(output))
      result = json.loads(output)
      print(result)
      print(type(result))
      return result
  if __name__ == '__main__':
        app.run(debug=True, host='localhost', port=81)
  </code></pre>
  <br>
  For now, I am just trying to print the dictionary in python output<br>
  <p>In console,JSON string looks like this : <code>{&quot;firstname&quot;:&quot;c&quot;,&quot;lastname&quot;:&quot;c&quot;}</code></p>
  <p>But I get this error right after:
  <code>POST http://localhost:81/test 404 (Not Found)</code></p>
  <p>I am very new to this, I think there is something wrong with the URL path in ajax.</p>
  <p>Files path are as follows:<br>
  index.html =&gt; localhost/index.html<br>app.py =&gt; localhost/venv/scripts/app.py</p>
  <p>How can I solve this issue?
  <br>Thank you.</p>