i know you can easily send form data to flask using calls like $.ajax() in jquery but what I need is a way to send data to a flask server using an element, say a <p> tag.
For example: test.html
<p data-rep='testentry' class='qtemp'>Entry00</p>
<p data-rep='testentry01' class='qtemp'>Entry01</p>
index.js
$(document).ready(function(){
$('.qtemp').on('click',function(){
var layout = $(this).data('rep');
$.ajax({
url: 'workstation',
type: 'POST',
data: layout
});
});
});
main.py
@app.route('/workstation',methods=['GET','POST'])
def workstation(data):
layout = data
return render_template('station.html',target=layout)
Running This App:
- Doesn't render the template
station.html - Doesn't print the
layoutvariable which contains the data sent (I added a print statement and it didn't work,even tried writing it to file)
What i've Tried:
- In
index.js, replacedata: layoutwithdata: JSON.stringify(layout)then in.main.py, replacelayout = datawithlayout = request.args.get('data').
needless to say, all of this doesn't work
NB: Using an html form is not an option
successcallback in your Ajax request, so the response is just silently ignored