Python Flask not receiving AJAX post?
<p>I have run into a problem with my javascript/python script. What I am trying to do is pass a string to python flask so I can use it later. When I click the button to send the string, there are no errors but nothing happens. I am basically a self taught coder so I apologise if my script it not properly formatted! </p>

<p>Javascript:</p>

<pre><code>$('#button').click(function() {
$.ajax({
   url:"/",
   type: 'POST',
   data: data,
   ...
</code></pre>

<p>Python Flask:</p>

<pre><code>from flask import Flask
from flask import request
from flask import render_template


app = Flask(__name__)


@app.route('/', methods=['POST', 'GET'])
def home():
    if request.method == "POST":
        string = request.args.get(data)
        print(string)
    return render_template('index.html')


if __name__ == '__main__':
    app.run(debug=True)
</code></pre>

<p>I want to be able to see the string printed to either the console or the command prompt, I assume print() is the right way to do this?
Any help would be welcome, thank you :)  </p>

<p>If you data object in Ajax is json then you can use <code>request.get_json()</code></p>

<p>If it is form data of key value then you can <code>request.form.get('data')</code> but your ajax should be </p>

<pre><code>$('#button').click(function() {
$.ajax({
   url:"/",
   type: 'POST',
   data: {data: 'mystring'},
</code></pre>

javascript python html ajax flask