您的位置:首页 > 理论基础 > 计算机网络

XMLHttpRequest+WebForm模式(接口IHttpHandler)实现ajax

2009-09-15 20:13 507 查看
首先引入ajax.js文件 创建xmlhttpRequest对象

<head runat="server">
<title>XMLHttpRequest+WebForm模式</title>
<script type="text/javascript" src="Ajax.js"></script>
</head>
<body>
<input type="text" id="txtName" />
<input type="button" value="Request" onclick="JavaScript:sendRequest();" />
<hr />
<div id="result"></div>
</body>
</html>
或者通过客户端向另一个页面传递参数,由该页面处理数据,把结果输出到http流中
apsx.cs页面
public partial class AjaxForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string name = Request.QueryString["name"];
Response.Write(name.ToUpper());
Response.Flush();
Response.End();
}
}
}

//xmlhttpRequest对象
//发起异步请求
function sendRequest(){
newXMLHttpRequest();
var url="AjaxForm.aspx?name="+document.getElementById("txtName").value;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=onSuccessCallBack;
xmlHttp.send(null);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐