diff --git a/flask/testapp/static/javascript/beautyVote.js b/flask/testapp/static/javascript/beautyVote.js index e8d3a75..b0a2999 100644 --- a/flask/testapp/static/javascript/beautyVote.js +++ b/flask/testapp/static/javascript/beautyVote.js @@ -60,6 +60,7 @@ switch(scene){ case 3: inputName(); + sendName(); break; case 1: @@ -120,23 +121,22 @@ if(50 <= tapX && tapX <= 450 && 300 <= tapY && tapY <= 550){ player.choice = A; - postForm(player.choice) // 送信用 + sendChoice(); checkAnswer(); } else if(500 <= tapX && tapX <= 900 && 300 <= tapY && tapY <= 550){ player.choice = B; - postForm(player.choice) // 送信用 + sendChoice(); checkAnswer(); - //document.getElementById('textBox').style.display = 'block'; } else if(50 <= tapX && tapX <= 450 && 600 <= tapY && tapY <= 850){ player.choice = C; - postForm(player.choice) // 送信用 + sendChoice(); checkAnswer(); } else if(500 <= tapX && tapX <= 900 && 600 <= tapY && tapY <= 850){ player.choice = D; - postForm(player.choice) // 送信用 + sendChoice(); checkAnswer(); } } @@ -168,6 +168,7 @@ } else{ scene = 2; + postForm(); } } @@ -190,11 +191,10 @@ // form.submit(); // } -function postForm(value){ - var xhr = new XMLHttpRequest(); +function postForm(){ xhr.open('POST', '/form'); xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); - xhr.send('username=' + player.name + '&data=' + player.choice); //変更 + xhr.send('username=' + player.name + '&score=' + player.calcScore()); //変更 xhr.onreadystatechange = function() { //受信用 if (xhr.readyState === 4 && xhr.status === 200) { if(xhr.responseText!="Data received successfully"){ @@ -208,6 +208,33 @@ } } +function sendChoice(){ + xhr.open('POST', '/form'); + xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); + xhr.send('choice=' + player.choice); //変更 + xhr.onreadystatechange = function() { //受信用 + if (xhr.readyState === 4 && xhr.status === 200) { + if(xhr.responseText!="Data received successfully"){ + console.log(xhr.responseText); + my_order=xhr.responseText + } + else{ + console.log(xhr.responseText); + } + } + } +} + +function sendName(){ + xhr.open('POST', '/form'); + xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); + xhr.send('username=' + player.name); //変更 +} + + + +var xhr = new XMLHttpRequest(); + var round = 0; var MAX_ROUND = 10; diff --git a/flask/testapp/templates/testapp/index.html b/flask/testapp/templates/testapp/index.html index fb09098..b310a32 100644 --- a/flask/testapp/templates/testapp/index.html +++ b/flask/testapp/templates/testapp/index.html @@ -39,7 +39,7 @@