diff --git a/app.py b/app.py index c3160be..54afc13 100644 --- a/app.py +++ b/app.py @@ -186,14 +186,16 @@ def predict(): @app.route('/add_letter', methods=['POST']) def add_letter(): - global word - global current_letter - if current_letter: - word += current_letter + data = request.get_json() - return "OK" + letter = data.get("letter", "") + + if letter: + word += letter + + return jsonify(success=True) @app.route('/undo_letter', methods=['POST']) diff --git a/templates/index.html b/templates/index.html index cf81b53..f0943d5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -403,10 +403,24 @@ function addLetter(){ - fetch('/add_letter',{ - method:'POST' - }).then(updateWord); - } + const displayedLetter = + currentLetter.textContent + .split(' ')[0]; + + fetch('/add_letter',{ + + method:'POST', + + headers:{ + 'Content-Type':'application/json' + }, + + body:JSON.stringify({ + letter: displayedLetter + }) + + }).then(updateWord); +} function undoLetter(){