我目前正在创建一个画布Javascript游戏,我将localstorage变量传递给我的数据库即Score。得分“已过去”。当我调试时,我看到localstorage值存在。但它似乎并没有存储到数据库中。最好不使用Ajax?
function drawElapsedTime(){
var elapsed=parseInt((new Date() - startTime)/1000);
g.save();
g.beginPath();
g.fillStyle="#008000";
g.font="14px Verdana"
// draw the running time at half opacity
g.globalAlpha=0.50;
g.fillText(elapsed+" secs",canvas.width-75,25);
localStorage.setItem("score",elapsed);
g.restore();
}
var storedTime = localStorage.getItem("score");
<form action="UserActionServlet" method="post">
<input type="submit" value="scoreObj" class="submit" />
</form>
命令:
String xscore = request.getParameter("score");
int score = 0;
if (xscore != null) {
score = Integer.parseInt(xscore);
}
System.out.println(xscore);
答案 0 :(得分:0)
您没有将得分变量作为参数传递给表单帖子。
<form action="UserActionServlet" method="post" onSubmit="submitForm(this.form)">
<input type = "hidden" name = "score"/>
<input type="submit" value="scoreObj" class="submit" />
</form>
<script>
function submitForm(f){
f.score.value = storedTime ;
f.submit();
}
</script>