I am trying to send data from javascript to flask when the user downloaded the file,
HTML:
<a href="/static/{{ot[0]}}" download>
<button type="button" class="btn" position="fixed" bottom="0px" right="0px" onclick="inc('{{ot[0]}}')">Download1</button>
</a>
<script type="text/javascript">
function inc(argsm){
var data1 = {'count': 1, 'name':argsm}
$.ajax({
type: "POST",
url:'/test',
data: JSON.stringify(data1),
dataType: 'json'
});
}
</script>
Flask
@app.route('/test', methods=['POST'])
def test():
print('test')
rf=request.form
print(rf)
for key in rf.keys():
data=key
print(data)
data_dic=json.loads(data)
print(data_dic.keys())
return redirect(url_for('home'))
This is not working, the ajax is not sending the data, help me to correct this, Is there any meta tag to add in head tag like connecting to ajax/jQuery link?
thanks
UPDATING ERROR -
GET http://127.0.0.1:5000/favicon.ico 404 (NOT FOUND)
home:34 Uncaught TypeError: $.ajax is not a function
at inc (home:34)
at HTMLButtonElement.onclick (home:86)
inc @ home:34
onclick @ home:86