發布一個超級mini的ajax原始碼(含簡單架構)

來源:互聯網
上載者:User
前2天做一個gis項目用到ajax,本來想用到ajaxpro,但有點問題又找不到原始碼,就依葫蘆畫瓢,寫了個類似的東東

:(含簡單架構和執行個體)
/Files/sukyboor/Ajax.rar

使用方法:
1。在web.config的system.web中加入
<!-- AJAX    -->
  <httpHandlers>
   <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
  </httpHandlers>
    
  2 AjaxTest.Br,AjaxTest表示業務處理類
   為該類需要在用戶端被調用的方法加入Ajax.AjaxMethod()屬性  

 1using System;
 2using Ajax;
 3
 4namespace AjaxTest
 5{
 6    /**//// <summary>
 7    /// Br 的摘要說明。
 8    /// </summary>
 9    public class Br
10    {
11
12        //得到表TableName的所得資料,以XML字串返回
13        [Ajax.AjaxMethod()]
14        public static string ShowMsg()
15        {
16            return "系統調用返回!";
17        }
18
19        //得到表TableName的所得資料,以XML字串返回
20        [Ajax.AjaxMethod()]
21        public  static string GetXmlDataRows(string t,string a,string b)
22        {
23            return string.Format("<?xml version=/"1.0/" encoding=/"utf-8/" ?><doc><t>{0}</t></doc>",t);
24        }
25    }
26}
27

3 在頁面中加入
    <script src="ajax/common.ashx" type="text/javascript"></script>
    <script src="ajax/AjaxScript.ashx?type=AjaxTest.Br,AjaxTest" type="text/javascript"></script>
   注意AjaxScript.ashx檔案的type就是要被調用的類,只要設定了type,那麼該類中所有屬性為Ajax.AjaxMethod()的方法在用戶端都可以訪問。<HTML>
    <HEAD>
        <script src="ajax/common.ashx" type="text/javascript"></script>
        <script src="ajax/AjaxScript.ashx?type=AjaxTest.Br,AjaxTest" type="text/javascript"></script>
        <script>        
        
            
            //最後一個參數是回調方法。和後台互動完成後觸發
            Br.GetXmlDataRows('xt_Name_t','a','測試資料',showmsg);
            Br.GetXmlDataRows('xt_Name_t','a','測試資料',showmsg);
            
            //回調用方法 s為後台傳回值
            function showmsg(s){
                var doc = new AjaxDom(s);
                document.write(doc.selectSingleNode("doc/t").text);
            }
            
            //如果無回調方法,系統會等待資料讀取。。。
            document.write(Br.ShowMsg());
            document.write(Br.ShowMsg());
        </script>
    </HEAD>
    <body>
    </body>
</HTML>

這個簡單吧,等哪天有空我把資料生存期和一些用戶端組件給移植過來,應該就像那麼回事了。 

http://sukyboor.cnblogs.com/archive/2006/07/21/456616.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.