我有一个使用自定义 do_GET 方法编写的 python 服务器来解析表单值。
我的目标是创建一个按钮,我可以将它放在一个表中,当它被击中时通知服务器并发送服务器可以解析的唯一键。按钮只需将预编程的密钥发送到服务器,因此实际上不需要用户可以输入的正常表单值。
我搜索了如何做到这一点,我发现了这个例子Posting a form with hidden fields without submit button click
我认为这会很好用,因为我可以使用 html 创建按钮,该按钮会调用我的 JS 以将“表单”提交到服务器。
我点击按钮,没有任何反应,我查看了我的谷歌浏览器控制台,我看到了以下错误:未捕获的错误:HierarchyRequestError:DOM Exception 3
然后我下载了 firefox 和 firebug,firebug 很好地遍历了我的代码,但这是我第一次使用它,我可能忽略了一些东西。
我的目标输出是让服务器接收这个获取请求
http://172.26.177.17/standardTable.html?TagID=00-00-11-AB-12
..或任何其他带有值 TagID 的消息
我的全部代码如下,您可能希望将操作更改为其他内容,但我认为其他所有内容都很好。
<!DOCTYPE html>
<html>
<head>
<title>Test Form</title>
<script type="text/javascript">
function createForm()
{
myform=document.createElement('form');
myform.method='get';
myform.action='http://172.26.177.17/standardTable.html';
input1=document.createElement('input');
input1.type='hidden';
input1.name='tagID';
input1.value='00-00-11-AB-12';
myform.appendChild(input1);
document.appendChild(myform);
myform.submit();
}
</script>
</head>
<body>
<button type="button" onclick="createForm()">Click Me</button>
</body>
</html>