Skip to content

Instantly share code, notes, and snippets.

@vvikramjhu
Last active December 20, 2015 22:38
Show Gist options
  • Save vvikramjhu/6206176 to your computer and use it in GitHub Desktop.
Save vvikramjhu/6206176 to your computer and use it in GitHub Desktop.
<!--trying to build the simplest of Json examples for pocoo. -->
<html>
<head></head>
<body>
<input tyep="text" id="test" name="test"/>
<a href=" " id="calculate">calculate</a>
<script type="text/javascript" src="/static/jquery.js"></script>
<script type="text/javascript" >
$(function(){
$("a#calculate").bind('click', function(){
$.getJSON('/get_total', {
test: $('input[name="test"]').val()
}, function(data){
alert("hello")
});
}); return false
});
</script>
</body>
</html>
#views.py--------------
@app.route('/get_total')
def get_total():
test = request.args.get('test')
test = "2013-08-11"
totalPrice = 0
cursor = g.db.cursor()
cursor.execute('select sum(price) from invoice where date= ? ',(test, ))
for row in cursor.fetchall():
totalPrice = row[0]
return jsonify(totalPrice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment