ajax 无刷新 显示
来源:互联网 发布:html视频播放器源码 编辑:程序博客网 时间:2024/05/01 11:29
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace HTML5
{
/// <summary>
/// Summary description for Sum
/// </summary>
public class Sum : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
int a = Convert.ToInt32(context.Request.QueryString["num1"]);
int b = Convert.ToInt32(context.Request.QueryString["num2"]);
int result = a + b;
context.Response.Write(result);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
<head>
<script language=jscript>
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function AddNumber()
{
createXMLHttpRequest();
var url= "http://localhost/agv/Sum.ashx?num1="+document.getElementById("num1").value+"&num2="+document.getElementById("num2").value;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=ShowResult;
xmlHttp.send(null);
}
function ShowResult()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
document.getElementById("sum").value=xmlHttp.responseText;
}
}
}
</script>
</head>
<body>
<div style="text-align: center">
<br />无刷新求和示例<br />
<br />
<input id="num1" style="width: 107px" type="text" onkeyup="AddNumber();" value="0" />
+<input id="num2" style="width: 95px" type="text" onkeyup="AddNumber();" value="0" />
=<input id="sum" style="width: 97px" type="text" /></div>
</body>
</html>
//**************************************************************
.ashx 文件用于写web handler的。其实就是带HTML和C#的混合文件。
同样.aspx也可以代替他的,不过在使用.aspx的时候必须得
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
不然返回的数据出了你需要的数据外,它还把它自身的html码和一起返回了.
- ajax 无刷新 显示
- Struts2-Ajax无刷新显示信息
- 用AJAX实现无刷新数据读取与显示
- 利用AJAX技术实现网页无刷新进度条显示
- 利用AJAX技术实现网页无刷新进度条显示
- 利用AJAX技术实现网页无刷新进度条显示
- 利用AJAX技术实现网页无刷新进度条显示
- 利用AJAX技术实现网页无刷新进度条显示
- 利用AJAX技术实现网页无刷新进度条显示
- 利用AJAX技术实现网页无刷新进度条显示
- 利用AJAX技术实现网页无刷新进度条显示
- 利用ajax技术实现网页无刷新进度条显示
- 利用AJAX技术实现网页无刷新进度条显示
- loner_li AJax 无刷新分页--显示数据库表内容 实例
- ajax无刷新技术
- ajax无刷新投票~~
- Ajax无刷新评论
- ajax局部无刷新
- 驱动开发(3)使用SCM加载NT驱动(用应用程序加载驱动)
- [LeetCode 174] Dungeon Game
- Preparement方法问题
- hdoj 4857 逃生
- win7jdk环境变量配置
- ajax 无刷新 显示
- 顺序表整体删除某值或某一区间
- memcached之java客户端:spymemcached与spring整合
- 性心理发展阶段
- 【Python3】error: Microsoft Visual C++ 10.0 is required 错误解决办法
- 从图片中的一点取色
- 华为P7如何官方解锁
- TCP状态迁移,CLOSE_WAIT & FIN_WAIT2 的问题
- 【Loadrunner】将乱码转译为中文方法
{
string strName = HttpContext.Current.Request.QueryString["name"];
string strRes = "服务器返回的响应信息:\r\n" +
"Hello, " + strName + "!";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strRes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}