Skip to content

Instantly share code, notes, and snippets.

@theycallmeswift
Created September 29, 2013 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theycallmeswift/6750562 to your computer and use it in GitHub Desktop.
Save theycallmeswift/6750562 to your computer and use it in GitHub Desktop.
from flask import Flask, request
app = Flask(__name__, static_folder='static', static_url_path='')
@app.route('/data', methods=['GET', 'POST'])
def post_data():
data = request.data # but data will be empty unless the request has the proper content-type header...
if not data:
data = request.form.keys()[0]
# mongo.db.test1_collection.insert({ city: data })
print data
return 'OK'
if __name__ == '__main__':
app.run(debug=True)
<html>
<head><title>Foo</title></head>
<body>
<h1 id="foo">New York</h1>
<script src="http://codeorigin.jquery.com/jquery-2.0.3.min.js"></script>
<script>
$(document).ready(function() {
$.post("/data", $("#foo").html(), function(data) { console.log(data) })
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment