1、添加对 AjaxPro.2.dll 的引用
2、在 webconfig 中 system.web 节点下 进行如下配置
<httpHandlers> <add verb="POST,GET" path="ajaxpro/*ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/> </httpHandlers>
3、注册类方法
[AjaxNamespace("myAjax")] public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { AjaxPro.Utility.RegisterTypeForAjax(typeof(WebForm1)); } [AjaxPro.AjaxMethod] public string sayHello(string name) { return name; } }
4、前台直接调用
<script type="text/javascript"> var val = myAjax.sayHello("Hello").value; alert(val); </script>