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);
}
<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);
}
相关文章推荐
- Comet4J(Comet for Java)是一个纯粹基于AJAX(XMLHTTPRequest)的服务器推送框架,消息以JSON方式传递,具备长轮询、长连接、自动选择三种工作模式。
- 玩转图片上传————原生js XMLHttpRequest 结合FormData对象实现的图片上传
- 用 jQuery.ajax 基于 XMLHttpRequest,FormData 的表单上传
- 使用XMLHTTPRequest和JQuery库实现AJax
- 使用xmlHttpRequest实现Ajax技术
- 使用XmlHttpRequest实现简单Ajax
- jQuery的ajax()检验用户名;通过jQuery的load()/get()/post()方法实现;使用XMLHTTPRequest对象来进行AJAX的异步数据交互
- 通过XMLHttpRequest和jQuery实现ajax的几种方式
- AJAX工作模式、XMLHttpRequest对象、运行流程
- AJAX和XmlHttpRequest下的Web开发
- 实现jquery.ajax及原生的XMLHttpRequest调用WCF服务的方法
- IHttpHandler、WebClient、HttpWebRequest的异步模式
- C#利用HttpWebRequest、HttpWebResponse调用12306接口,实现登录、查票、买票。
- 利用XMLHttpRequest(XHR)对象实现与web服务器通信
- 掌握 Ajax,第 2 部分: 使用 JavaScript 和 Ajax 发出异步请求 在 Web 请求中使用 XMLHttpRequest
- Ajax-05 使用XMLHttpRequest和jQuery实现Ajax实例
- 利用XMLHttpRequest对象编写实现Ajax小实例
- 系统地学习ASP.NET AJAX(8) - 客户端脚本编程(Sys.Net命名空间下的WebRequestManager、WebRequest、WebRequestExecutor和XMLHttpExecutor)
- 通过XMLHttpRequest和jQuery实现ajax的几种方式
- Ajax实例:实现查找员工和新建员工,利用XMLHttpRequest对象实现前后端交互