ajax无翻页刷新简单实例2
来源:互联网 发布:玛吉史密斯知乎 编辑:程序博客网 时间:2024/06/04 18:50
1,HTML页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>微博样式1</title>
</head>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function addNumber()
{
createXMLHttpRequest();
//var url= "AjaxMicrobloggingPaging.aspx?Num1="+document.getElementById("num1").value+"&Num2="+document.getElementById("num2").value;
var url= "Handler.ashx";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=showResult;
xmlHttp.send(null);
}
function showResult()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
document.getElementById("mlist").innerHTML=xmlHttp.responseText;
}
}
}
</script>
<body>
<div class="content" id="mlist"></div>
<input type="button" name="fdfds" value="计算" onclick="addNumber();" />
</body>
</html>
2,动态页面
<%@ WebHandler Language="C#" class="Handler" %>
using System;
using System.Web;
using System.Text;
using System.Data;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write(server_Side_Processing(5, 1));
}
public bool IsReusable {
get {
return false;
}
}
/// <summary>
///服务器端处理程序到数据库查询数据并生成xml档返回
/// </summary>
public string server_Side_Processing(int pageSize, int currentPage)
{
StringBuilder resultXML = new StringBuilder();
string str_xml;
DataSet ds;
DataAccess da;
int i;
resultXML.Append("<?xml version='1.0' encoding='gb2312'?>");
resultXML.Append("<ajax-response>\n");
resultXML.Append("<root>\n");
try
{
if (currentPage == 1)
{
str_xml = "select top " + pageSize + " * from tbMicroblog order by MicroblogID desc";
}
else
{
str_xml = "select top " + pageSize + " * from tbMicroblog MicroblogID not in (select top " + pageSize * (currentPage - 1) + " * from tbMicroblog order by MicroblogID desc) where order by MicroblogID desc";
}
da = new DataAccess();
ds = da.GetDataSetResult(str_xml, "xml_table");
if (ds != null)
{
for (i = 0; i < pageSize; i++)
{
if (ds.Tables[0].Rows[i] == null)
{
break;
}
resultXML.Append("<data>\n");
resultXML.Append("\t<MicroblogID>" + ds.Tables[0].Rows[i]["MicroblogID"].ToString() + "</MicroblogID>\n");
if (ds.Tables[0].Rows[i]["UserID"].ToString().Trim() != "")
{
resultXML.Append("\t<UserID>" + HttpUtility.UrlEncodeUnicode(ds.Tables[0].Rows[i]["UserID"].ToString().Trim()) + "</UserID>\n");
}
else
{
resultXML.Append("\t<UserID>#</UserID>\n");
}
if (ds.Tables[0].Rows[i]["Content"].ToString().Trim() != "")
{
resultXML.Append("\t<Content>" + HttpUtility.UrlEncodeUnicode(ds.Tables[0].Rows[i]["Content"].ToString().Trim()) + "</Content>\n");
}
else
{
resultXML.Append("\t<Content>#</Content>\n");
}
if (ds.Tables[0].Rows[i]["Pubdate"].ToString().Trim() != "")
{
resultXML.Append("\t<Pubdate>" + HttpUtility.UrlEncodeUnicode(ds.Tables[0].Rows[i]["Pubdate"].ToString().Trim()) + "</Pubdate>\n");
}
else
{
resultXML.Append("\t<Pubdate>#</Pubdate>\n");
}
resultXML.Append("</data>\n");
}
}
else
{
resultXML.Append("<data>\n");
resultXML.Append("\t<nodata>" + "No Data !" + "</nodata>\n");
resultXML.Append("</data>\n");
}
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
resultXML.Append("</root>\n");
resultXML.Append("</ajax-response>");
return resultXML.ToString();
}
}
- ajax无翻页刷新简单实例2
- jquery+ajax无刷新翻页
- Ajax简单实例----无刷新求和运算
- ajax无刷新实例
- 页码js,支持ajax无刷新翻页
- jquery ajax无刷新翻页 分页
- PHP Ajax 页面无刷新 翻页
- strtuts+ajax 用户名无刷新验证简单实例
- 无刷新提交表单(php+js+ajax简单实例 )
- Jquery, Ajax无刷新翻页,支持跳转页面
- Java数据采集-7.Ajax无刷新请求(翻页-3)
- jquery 无刷新翻页
- jquery无刷新翻页,无翻页效果
- ajax静态页面无刷新添加留言,无刷新分页,翻页综合应用
- ajax静态页面无刷新添加留言,无刷新分页,翻页综合应用
- Ajax的无刷新技术实例详解
- AJAX+jsp无刷新验证码实例
- AJAX+jsp无刷新验证码实例
- 设为主页代码及添加到收藏夹代码大全
- m-s的半同步设置
- SWFUPLOAD上传错误的解决方法
- 第六届ACM省赛--宋金学
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
- ajax无翻页刷新简单实例2
- jQuery之ajax删除
- 在Repeter中用RadioButton生成单选按钮组的实现
- IOS 获取设备的信息
- asp.net 使用UpdatePanel 返回服务器处理后弹出对话框
- 一种夜间模式简单实现方案
- 在Updatepanel中使用Response.Redirect
- spring websocket + stomp 实现广播通信和一对一通信
- jQuery Tips(5)----关于伪类选择符