<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<p><span id="A1"></span></p>
<button onclick="sendformdata()">发送数据</button>
<script type="text/javascript">
var xmlhttp;
function sendformdata()
{
if (window.XMLHttpRequest) { // Mozilla 浏览器 //新建XMLHttpRequest对象
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 浏览器
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) { }
}
}
if (xmlhttp!=null)
{
var formData = new FormData();
formData.append('username','lee');
formData.append('usercity','beijing');
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open('POST','showinfo.asp');
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(formData);
}
else
{
alert("您的浏览器不支持 XMLHTTP.");
}
}
function state_Change()
{
if (xmlhttp.readyState==4) // 服务器已经响应
{
if (xmlhttp.status==200) // 请求成功
{
// 显示服务器的响应数据
document.getElementById('A1').innerHTML=xmlhttp.responseText;
}
else
{
alert("接收XML数据时出现问题:" + xmlhttp.statusText);
}
}
}
</script>
</body>
</html>
后台showinfo.asp 接收数据并显示
showinfo.asp 的代码如下:
<%@LANGUAGE="VBSCRIPT" codepage="65001"%>
<%
username=request.form("username")
usercity=request.form("usercity")
response.write "名字:" & username&"<br>"
response.write "城市:" & username&"<br>"
%>
执行完第一个程序后,显示不出来传递的数据:lee 和Beijing
请教了,谢谢!!!
请教使用FormData向服务器发送不了数据。 代码如下:
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答
- Go 旅城通票 2017-08-11 02:07关注
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
去掉这个解决 无用评论 打赏 举报
悬赏问题
- ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
- ¥15 活动选择题。最多可以参加几个项目?
- ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
- ¥15 vs2019中数据导出问题
- ¥20 云服务Linux系统TCP-MSS值修改?
- ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
- ¥20 怎么在stm32门禁成品上增加查询记录功能
- ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
- ¥50 NT4.0系统 STOP:0X0000007B
- ¥15 想问一下stata17中这段代码哪里有问题呀