第一个XMLHTTP测试成功![原创]

本文提供了一个使用XMLHttpRequest进行POST请求的HTML与ASP.NET示例。通过按钮触发,将输入框内容发送到服务器端并接收反馈。服务器端使用C#处理请求参数并返回定制消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

testxmlhttp.html
None.gif<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
None.gif
<html xmlns="http://www.w3.org/1999/xhtml" >
None.gif
<head>
None.gif    
<title>XmlHttp测试</title>
ExpandedBlockStart.gifContractedBlock.gif    
<script type="text/javascript">dot.gif
InBlock.gif    
function testxml()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
InBlock.gif        xmlhttp.open('POST','xmlhttp.aspx
?name='+document.getElementById('Text1').value,false);
InBlock.gif        xmlhttp.send();
InBlock.gif        alert(xmlhttp.responseText);
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif    
</script>
None.gif
</head>
None.gif
<body>
None.gif    
<input id="Text1" maxlength="20" type="text" />
None.gif    
<input id="Button1" type="button" value="button"  onclick="testxml()"/>
None.gif
</body>
None.gif
</html>
None.gif
xmlhttp.aspx没有内容
xmlhttp.aspx.cs
None.gifusing System;
None.gif
using System.Data;
None.gif
using System.Configuration;
None.gif
using System.Collections;
None.gif
using System.Web;
None.gif
using System.Web.Security;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.WebControls.WebParts;
None.gif
using System.Web.UI.HtmlControls;
None.gif
None.gif
public partial class xmlhttp : System.Web.UI.Page
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (Request.QueryString["name"!= null
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Clear();
InBlock.gif            Response.Write(
"您好:"+Request.QueryString["name"].ToString());
InBlock.gif            Response.Flush();
InBlock.gif            Response.End();
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/ghx88/archive/2006/06/15/426216.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值