running a python script within Flask
<p>So I have this simple python script running on Flask that I'd like to pass variables to with an ajax jQuery request. I might be missing something obvious but I can't get it to work properly. </p>

<pre><code>@app.route('/test', methods=['GET', 'POST'])
def test():
    my_int1 = request.args.get('a')
    my_int2 = request.args.get('b')
    my_list = [my_int1, my_int2]
    with open('my_csv.csv', 'wb') as myfile:
        wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
        wr.writerow(my_list)
    return '' #does one have to have an return even tho it is just a script?
</code></pre>

<p>So, above will work fine when just passing parameters to the URL field: <code>http://127.0.0.1:5000/test?a=10&amp;b=25</code> however, trying this in the chrome console will not yield any output at all: </p>

<pre><code>$.ajax({
  method: "POST",
  url: "127.0.0.1:5000/test",
  data: {a: 10, b: 25},
  dataType: "script"
});
</code></pre>

<p>What am I missing and why does the above jquery ajax request not work? <code>$.ajax is not a function(â¦)</code></p>

<p>Please refer to <a href="http://flask.pocoo.org/docs/0.11/api/#flask.Request" rel="nofollow">http://flask.pocoo.org/docs/0.11/api/#flask.Request</a></p>

<pre><code>request.args : If you want the parameters in the URL
request.form : If you want the information in the body (as sent by a html POST form)
request.values : If you want both
</code></pre>

<p>Try this</p>

<pre><code>@app.route('/test', methods=['GET', 'POST'])
def test():
    my_int1 = request.values.get('a')
    my_int2 = request.values.get('b')
</code></pre>

jquery python ajax flask