开发者

URL parameters not getting passed during javascript submit

开发者 https://www.devze.com 2023-04-04 05:18 出处:网络
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.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消