在web开发中,经常会用到简单Ajax技术,本文将介绍一种简单Ajax使用方法。
1. 资源文件
我们将使用一开源的Ajax组件Ajaxpro.dll,dll文件下载链接如下:
2. 使用方法
a) 在web.config配置文件中添加<httpHandlers>节点。在web.config的<system.web>节点中加入如下的代码即可:
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
</httpHandlers>
</system.web>
b) 在页面的Page_Load方法中注册脚本。
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(注册类的完整名称));
......
}
c) 编写注册类要使用Ajax的方法。可以返回简单对象,也可以返回自定义对象。
[AjaxPro.AjaxMethod]
public IList<JobInfo> GetAllJobsByCondition(string deptNo)
{
IList<JobInfo> result = InterviewManager.Instance.GetAllJobsByDeptNo(deptNo);
return result;
}
d) 用脚本调用Ajax方法。返回值为object对象,需要取其value属性才是真正的返回值。
var result =注册类的完整名称. GetAllJobsByCondition ("para");
if(result.value != null) {...... }
3. 官方网址
更多请参考官方网址:http://www.ajaxpro.info/