I'm having a bit of trouble with figuring out how to get a post from Javascript to work, to my Python Flask server.
Here's the important part of what I've got in my html file
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js </script>
<script type=text/javascript>
$('a#test').bind('click', function() {
var textBox = document.getElementById('targetTextArea').value;
$.post('/postmethod', {text: textBox} );
});
</script>
<!--textarea-->
<textarea rows="1" cols="20" id="targetTextArea">
</textarea>
<!--button-->
<form method="post" role="form">
<a href=# id=test>
<input type="button" value="submit" id="submit" onClick="writeOut()">
</a>
</form>
and here's what I've got in my Python flask file
@app.route('/postmethod', methods = ['POST'])
def postmethod():
data = request.form['text']
print "Hello world!"
print data
return data
When I run my python script the textarea and button are there as they should be, but when I type into the textarea and click the button nothing is printed. Please help.
method="post"to your<form>tag because the jQuery code already calls$.post(...)