diff options
| author | Yuval Adam <yuv.adm@gmail.com> | 2014-05-30 14:22:37 +0300 |
|---|---|---|
| committer | Yuval Adam <yuv.adm@gmail.com> | 2014-05-30 14:22:37 +0300 |
| commit | 6b30efcaa6352f85b6b82776522066fff6e303d8 (patch) | |
| tree | 0cbb0c9cda218668ad0fc57829abed2458522e93 | |
| parent | 214473c650918282ec4bceee883f3bcd86a1bc3d (diff) | |
Initial load data
| -rw-r--r-- | server.py | 7 | ||||
| -rw-r--r-- | templates/home.html | 4 |
2 files changed, 5 insertions, 6 deletions
@@ -1,8 +1,6 @@ -import json - from datetime import datetime from flask import Flask -from flask import render_template, request +from flask import json, jsonify, render_template, request from unipath import FSPath as Path DATA_DIR = Path(__file__).absolute().ancestor(1).child('data') @@ -16,7 +14,8 @@ def home(): @app.route('/data', methods=['POST', 'GET']) def data(): if request.method == 'GET': - return 'hai' + with open(DATA_DIR.child('data.json'), 'r') as f: + return jsonify(json.load(f)) elif request.method == 'POST': ts = datetime.now().strftime('%Y%m%d_%H%M%S') for filename in ('data.json', 'data.{}.json'.format(ts)): diff --git a/templates/home.html b/templates/home.html index 0d7b4f5..f3cf800 100644 --- a/templates/home.html +++ b/templates/home.html @@ -11,9 +11,9 @@ <script src="/static/js/bootstrap.min.js"></script> <script src="/static/js/bootstrap-slider.min.js"></script> <script> - function get_data() { + function load_data() { $.get('/data', function(res) { - alert(res); + console.log(res); }); }; |
