博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

AJAX.PRO 简单事例

Posted on 2007-12-03 15:20  孤峰皓月  阅读(529)  评论(0编辑  收藏  举报

如果你用的是.NET2.0,且不用VS2005的话。你只需要把AjaxPro.2.dll放入应用程序的bin文件夹中,而且也只需要如下几步:

1、修改web.config

在system.web节点下添加

<system.web>
    <httpHandlers>
      <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>
    </httpHandlers>

2、将你的.NET方法添加AjaxMethod属性

[AjaxPro.AjaxMethod]
public DateTime GetServerTime()
{
  return DateTime.Now;
}


============下面是我自己做的一个例子......完整,只说明了如何实现客户端访问服务端函数
 1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestAjaxPro.aspx.cs" Inherits="test_TestAjaxPro" %>
 2
 3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 4
 5<html xmlns="http://www.w3.org/1999/xhtml" >
 6<head runat="server">
 7    <title>无标题页</title>
 8    <script type="text/javascript">
 9    
10        function getServerTime()
11        {
12            test_TestAjaxPro.GetServerTime(getServerTime_callback);
13        }

14        
15        function getServerTime_callback(res)
16        {
17            alert(res.value);
18        }

19        
20    
</script>
21</head>
22<body>
23    <form id="form1" runat="server">
24    <div>
25        <input type="button" onclick="getServerTime();" value="测试AJAX PRO" />
26    </div>
27    </form>
28</body>
29</html>
30


 1using System;
 2using System.Data;
 3using System.Configuration;
 4using System.Collections;
 5using System.Web;
 6using System.Web.Security;
 7using System.Web.UI;
 8using System.Web.UI.WebControls;
 9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12using AjaxPro;
13
14public partial class test_TestAjaxPro : System.Web.UI.Page
15{
16    protected void Page_Load(object sender, EventArgs e)
17    {
18        AjaxPro.Utility.RegisterTypeForAjax(typeof(test_TestAjaxPro));  //在.NET方法中向客户端注册javascript,用以javascript使用
19    }

20
21    [AjaxPro.AjaxMethod]
22    public string GetServerTime()
23    {
24        return "现在时间是:" + DateTime.Now;
25    }

26
27}

28