原文地址:http://www.ajaxpro.info/quickguide.aspx
AjaxPro快速入门
因为我不可能写很大段使用文档,所以在这文章里只是告诉大家如何上手使用AjaxPro:
- 大家可以从 www.schwarz-interactive.de 下载最新的 Ajax.NET Professional 文件
- 给你的项目添加引用 AjaxPro.2.dll (如果是.NET 1.1 Framework 请使用AjaxPro.dll)
- 在你的 web.config添加入下内容:
<?xml version="1.0" encoding="utf-8" ?> <configuration><system.web><httpHandlers><add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/></httpHandlers>[...]</system.web> </configuration>
- 现在你可以使用AjaxMethod属性添加你的.NET 方法 :
[AjaxPro.AjaxMethod]
public DateTime GetServerTime()
{return DateTime.Now;
}
- 要在客户端使用JavaScript 来调用你的.net方法,你必注册你的页面类到Ajax.NET:
namespace MyDemo
{public class _Default{protected void Page_Load(object sender, EventArgs e){AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));}[AjaxPro.AjaxMethod]public DateTime GetServerTime(){return DateTime.Now;}}
}
- 你可以在客户端使用JavaScript的异步方式来调用你的.net方法:
function getServerTime()
{MyDemo._Default.GetServerTime(getServerTime_callback); // asynchronous call
}// 此方法执行后将调用下面的方法
// 结果将会返回给客户端function getServerTime_callback(res)
{alert(res.value);
}
- 你也可以在客户端使用JavaScript的同步方式来调用你的.net方法:
function getServerTime()
{alert(MyDemo._Default.GetServerTime().value;
}