Last active
November 15, 2018 06:18
-
-
Save u1and0/658baeecf658cd05eea4d69e533f957e to your computer and use it in GitHub Desktop.
Flask + jQueryでテーブルの入力フォームに入力があるたびに値を取得 ref: https://qiita.com/u1and0/items/6dcfdf60b02eba207064
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(function ($){ | |
| // テーブルの入力フォームにインプットした際に発動 | |
| $('td input').on('input',function () { | |
| // name属性と入力フォームの値を取得 | |
| var inp = {name: $(this).attr('name'), | |
| value: $(this).val()}; | |
| console.log(inp); // 入力をjavascriptでコンソールに表示 | |
| inp = JSON.stringify(inp); | |
| $.post({ | |
| url: '{{ url_for('complete') }}', // server.py complete()に渡す | |
| data: inp, | |
| dataType: 'json', | |
| contentType: 'application/json;charset=UTF-8', | |
| }).done(function(data){ | |
| console.log(data); // 入力をserver.pyを通して表示 | |
| }).fail(function(){ | |
| console.log('fail'); | |
| }); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask | |
| from flask import render_template | |
| from flask import request | |
| from flask import jsonify | |
| from flask_bootstrap import Bootstrap | |
| (略) | |
| @app.route('/complete', methods=['POST']) | |
| def complete(): | |
| json_data = request.json | |
| return jsonify({'value': json_data}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment