表单数据未发布到服务器
Formdata not posted to server
我在 post 向服务器发送表单数据时遇到问题。
我首先测试了如何实施 post 合并 javascript 和 asp 的表单数据并成功!!! :-)
所以,非常典型 - 将此策略实施到实际代码中失败了!!! :-(
代码的不同之处在于,在后者中,我动态创建了复选框,url 有点不同 - 这是相同的 ip,但有一些参数。
我几乎可以肯定 posting 失败了,因为我可以在 wirechark 中看到这一点 - 分析包。在第一种情况下 - 我可以将选中的项目视为以逗号分隔的字符串。在后者中 - 我看不到复选框数据的任何字符串项。
第一个代码(有效)
<!DOCTYPE html>
<html>
<body>
<form action="jstest.asp" method="post" name="myform">
<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle" value="Car" checked> I have a car<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
<%
description = request.form("vehicle")
response.write("sort = " & description)
%>
无效的代码
<form action="?dep=enviro&page=room&func=attach_objekt" method="post">
<script type="text/javascript">
<%for i = 0 to UBound(objArray) - 1%>
var x = document.createElement("INPUT");
x.setAttribute("type", "checkbox");
x.setAttribute("value", "car");
x.setAttribute("name", "vehicle");
var y = document.createElement("label");
y.innerHTML = "<%=objArray(i)%>";
y.id="label_<%=objArray(i)%>";
document.body.appendChild(x);
document.body.appendChild(y);
<%next%>
</script>
<input type="submit" value="Submit">
</form>
将您的元素附加到表单而不是正文中。
通过替换
尝试下面的代码
document.body.appendChild(x);
document.body.appendChild(y);
至
document.forms['yourFormName'].appendChild(x);
document.forms['yourFormName'].appendChild(y);
我在 post 向服务器发送表单数据时遇到问题。
我首先测试了如何实施 post 合并 javascript 和 asp 的表单数据并成功!!! :-)
所以,非常典型 - 将此策略实施到实际代码中失败了!!! :-(
代码的不同之处在于,在后者中,我动态创建了复选框,url 有点不同 - 这是相同的 ip,但有一些参数。
我几乎可以肯定 posting 失败了,因为我可以在 wirechark 中看到这一点 - 分析包。在第一种情况下 - 我可以将选中的项目视为以逗号分隔的字符串。在后者中 - 我看不到复选框数据的任何字符串项。
第一个代码(有效)
<!DOCTYPE html>
<html>
<body>
<form action="jstest.asp" method="post" name="myform">
<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle" value="Car" checked> I have a car<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
<%
description = request.form("vehicle")
response.write("sort = " & description)
%>
无效的代码
<form action="?dep=enviro&page=room&func=attach_objekt" method="post">
<script type="text/javascript">
<%for i = 0 to UBound(objArray) - 1%>
var x = document.createElement("INPUT");
x.setAttribute("type", "checkbox");
x.setAttribute("value", "car");
x.setAttribute("name", "vehicle");
var y = document.createElement("label");
y.innerHTML = "<%=objArray(i)%>";
y.id="label_<%=objArray(i)%>";
document.body.appendChild(x);
document.body.appendChild(y);
<%next%>
</script>
<input type="submit" value="Submit">
</form>
将您的元素附加到表单而不是正文中。
通过替换
尝试下面的代码document.body.appendChild(x);
document.body.appendChild(y);
至
document.forms['yourFormName'].appendChild(x);
document.forms['yourFormName'].appendChild(y);