JavaScript 提交期间未传递 URL 参数
我正在尝试从 javascript 提交表单。表单已提交,但参数未传递。下面是我的代码。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Tic Tac Toe</title>
<script type="text/javascript">
function selection(selected){
theform = window.document.tictactoe;
theform.action="GameAction?selection="+selected.id;
theform.submit();
}
</script>
</head>
<body>
<form name="tictactoe" id="tictactoe" method="GET" action="GameAction">
<table border="1">
<tr><td><img id="0,0" src="images/white.JPG" onclick="selection(this);"></img></td><td><img id="0,1" src="images/white.JPG" onclick="selection(this);"></img></td><td><img id="0,2" src="images/white.JPG" onclick="selection(this);"></img></td></tr>
<tr><td><img id="1,0" src="images/white.JPG" onclick="selection(this);"></img></td><td><img id="1,1" src="images/white.JPG" onclick="selection(this);"></img></td><td><img id="1,2" src="images/white.JPG" onclick="selection(this);"></img></td></tr>
<tr><td><img id="2,0" src="images/white.JPG" onclick="selection(this);"></img></td><td><img id="2,1" src="images/white.JPG" onclick="selection(this);"></img></td><td><img id="2,2" src="images/white.JPG" onclick="selection(this);"></img></td></tr>
</table>
</form>
</body>
</html>
如果有人可以帮助解决这个问题,那就太好了。
I am trying to do a form submit from javascript. The form gets submitted but the parameters are not getting passed. Below is my code.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Tic Tac Toe</title>
<script type="text/javascript">
function selection(selected){
theform = window.document.tictactoe;
theform.action="GameAction?selection="+selected.id;
theform.submit();
}
</script>
</head>
<body>
<form name="tictactoe" id="tictactoe" method="GET" action="GameAction">
<table border="1">
<tr><td><img id="0,0" src="images/white.JPG" onclick="selection(this);"></img></td><td><img id="0,1" src="images/white.JPG" onclick="selection(this);"></img></td><td><img id="0,2" src="images/white.JPG" onclick="selection(this);"></img></td></tr>
<tr><td><img id="1,0" src="images/white.JPG" onclick="selection(this);"></img></td><td><img id="1,1" src="images/white.JPG" onclick="selection(this);"></img></td><td><img id="1,2" src="images/white.JPG" onclick="selection(this);"></img></td></tr>
<tr><td><img id="2,0" src="images/white.JPG" onclick="selection(this);"></img></td><td><img id="2,1" src="images/white.JPG" onclick="selection(this);"></img></td><td><img id="2,2" src="images/white.JPG" onclick="selection(this);"></img></td></tr>
</table>
</form>
</body>
</html>
It would be great if someone could help in resolving this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当通过“get”提交表单时,浏览器获取表单的值,从中生成查询字符串,然后将窗口发送到该位置。如果那里已经有一个查询字符串,它不仅仅会附加新值..它还会将它们删除。如果您将该方法更改为“post”,您会注意到它实际上添加了您想要添加到 URL 的数据。由于我不确定您的最终结果到底是什么,我至少希望这些信息对您有所帮助。这只是基于经验,因此其他人可能有更多的技术见解。
When the form gets submited through 'get', the browser takes the values of the form, makes a query string out of it and then sends the window to that location. If there was already a query string there, it doesn't just append the new values.. it wipes them out. If you change the method to a 'post', you'll notice that it does in fact add that data you wanted to have added to the URL. Since I'm not sure what exactly your end result really is, I at least hope this information helps you out. It's just based off experience, so others might have more technical insights.