最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
ajax简单应用代码
时间:2011-03-03 编辑:简简单单 来源:一聚教程网
ajax简单应用代码
@ webhandler language="c#" class="handler" %>
using system;
using system.web;
using system.collections.generic;
using system.data;
public class handler : ihttphandler
{
public void getpage( httpcontext context)
{
int pagenum = convert.toint32(context.request["pagenum"]);
pagenum++;
if (pagenum <= 3)
{
dataset1.productdatatable cachedata =
(dataset1.productdatatable)context.cache["cachekey"];
if (cachedata == null)
{
cachedata = new
dataset1tableadapters.producttableadapter().getdatabypriceasc(1, 15);
context.cache.insert("cachekey", cachedata, null,
system.web.caching.cache.noabsoluteexpiration, timespan.fromseconds
(80));
}
list
for (int i = (pagenum * 5) - 4; i <= pagenum * 5; i++)
{
dataset1.productrow row = cachedata[i - 1];
string s = link.toproduct(row.productid.tostring());
news.add(new product()
{
name = row.name,
description = row.description,
price = row.price.tostring(),
thumbnail = row.thumbnail,
path = s
});
}
system.web.script.serialization.网页特效serializer jss =
new system.web.script.serialization.网页特效serializer();
context.response.write(jss.serialize(news));
}
else
{
var data = new
dataset1tableadapters.producttableadapter().getdatabypriceasc((pagenum *
5) - 4, pagenum * 5);
list
for (int i =0; i <5; i++)
{
dataset1.productrow row = data[i];
string s = link.toproduct(row.productid.tostring());
news.add(new product()
{
name = row.name,
description = row.description,
price = row.price.tostring(),
thumbnail = row.thumbnail,
path = s
});
}
system.web.script.serialization.javascriptserializer jss
= new system.web.script.serialization.javascriptserializer();
context.response.write(jss.serialize(news));
}
}
public void processrequest (httpcontext context)
{
context.response.contenttype = "text/plain";
string action = context.request["action"];
if (action == "getpage")
{
int allcount = new
dataset1tableadapters.producttableadapter().getcount().value;
context.response.write(allcount);
}
else if (action == "getpagedateasc")
{
getpage("getpagedateasc", context);
}
else if (action == "getpagedatedesc")
{
getpage("getpagedatedesc", context);
}
}
public bool isreusable
{
get
{
return false;
}
}
}
public class product
{
public string name { set; get; }
public string description { set; get; }
public string price { set; get; }
public string thumbnail { set; get; }
public string path { set; get; }
}
html代码//http://www.3ppt.com/design/asp教程x/38279.html
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
rel="stylesheet" type="text/css" />
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
rel="stylesheet" type="text/css" />
(把dropdownlist改为客户端html控件select,然后用ajax存储,肯定不会有错误
,但是这里表单有很多需要提交的数据,所以不考虑用客户端html控件)
1、在页面的<%@ page language="c#" autoeventwireup="true"
codefile="default.aspx.cs" inherits="_default" %> 中添加
enableeventvalidation="false";
2、在页面添加隐藏域
,然后用js将dropdownlist选择后的值赋值给隐藏域,
这样后台就可以通过 inputcity.value 来读取到隐藏域的值,也就是省市选择的
值了
s="digg" style="float:left"/>
相关文章
- 应用接口之:Ajax 的简单方法 08-30
- ajax框架瑟xajax简单介绍 12-20
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
热门栏目
-
php教程
php入门 php安全 php安装 php常用代码 php高级应用 -
asp.net教程
基础入门 .Net开发 C语言 VB.Net语言 WebService -
手机开发
安卓教程 ios7教程 Windows Phone Windows Mobile 手机常见问题 -
css教程
CSS入门 常用代码 经典案例 样式布局 高级应用 -
网页制作
设计基础 Dreamweaver Frontpage js教程 XNL/XSLT -
办公数码
word excel powerpoint 金山WPS 电脑新手 -
jsp教程
Application与Applet J2EE/EJB/服务器 J2ME开发 Java基础 Java技巧及代码