1.引入dll到bin目录下2.web.config: <system.web> 内加入<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>
</httpHandlers>3.使用:后台:page_load里加入注册AjaxPro.Utility.RegisterTypeForAjax(typeof(ajax方法所在的类名)); ajax方法编写(在上面提到的注册的类里)[AjaxPro.AjaxMethod]
public string Getdbdata()
{
return HttpContext.Current.Application["abc"].ToString();
}// [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)] 这样可以操作session 前台脚本调用:注册过的页面的脚本function fun1()
{
var text=<注册过的ajax方法所在类>.<ajax方法()>.value;
alert(text);}
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>
</httpHandlers>3.使用:后台:page_load里加入注册AjaxPro.Utility.RegisterTypeForAjax(typeof(ajax方法所在的类名)); ajax方法编写(在上面提到的注册的类里)[AjaxPro.AjaxMethod]
public string Getdbdata()
{
return HttpContext.Current.Application["abc"].ToString();
}// [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)] 这样可以操作session 前台脚本调用:注册过的页面的脚本function fun1()
{
var text=<注册过的ajax方法所在类>.<ajax方法()>.value;
alert(text);}
----------------------------------------------------------------------------Ajax实现局部刷新
<script type="text/javascript">
var xmlhttp;
function getData()
{
//获取用户填写的名称
var city=document.getElementById("txt").value;
//创建异步调用对象
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
//将对象状态与事件相关联
xmlhttp.onreadystatechange=statechange;
//加载要链接的页面
xmlhttp.Open("POST","datapage.aspx?city=" +city,true);
//发送请求
xmlhttp.Send();
}
function statechange()
{
//判断异步调用是否已经完成
if(xmlhttp.readystate==4)
{
//判断完成的提示代码是否是OK状态
if(xmlhttp.status==200)
{
//将返回数据作为参数,传递给填充方法
FillData(xmlhttp.responseText);
}
}
}
function FillData(strcity)
{
document.getElementById("DropDownList1").options.length=0;
var indexofcity;
var city;
//切割传递来的字符串
while(strcity.length>0)
{
//判断是否是最后一个字符串
indexofcity=strcity.indexOf(",");
if(indexofcity >0)
{
city=strcity.substring(0,indexofcity);
strcity=strcity.substring(indexofcity+1);
//填充下拉框
document.getElementById("DropDownList1").add(new Option(city,city));
}
else
{
// 如果是最后一个字符串
lastcity=strcity.substring(0,2);
document.getElementById("DropDownList1").add(new Option(lastcity,lastcity));
break;
}
};
}
</script>
网上找的一段代码,楼主也可以用微软的asp.net ajax 1.0...那个实现起来更方便