JavaScript 提交期间未传递 URL 参数

发布于 2024-12-04 03:28:33 字数 1648 浏览 2 评论 0原文

我正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吝吻 2024-12-11 03:28:33

当通过“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文