如果你用的是.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