AJAX.NET使用基礎

來源:互聯網
上載者:User

AjaxPro.Utility.RegisterTypeForAjax(typeof(Resin));
使用上面的方法註冊當前頁面,運行後在頁面中加入下面兩句
<script type="text/javascript" src="/AJAXDemo/ajaxpro/core.ashx"></script>
<script type="text/javascript" src="/AJAXDemo/ajaxpro/AJAXDemo.Resin,AJAXDemo.ashx"></script>

      <script language="javascript">
        var response = Sample.ServerSideAdd(100,99);
        alert(response.value);
      </script>

增加用戶端可調用方法
  public int ServerSideAdd(int firstNumber, int secondNumber)
  {
   return firstNumber + secondNumber;
  }

用戶端調用
  <form id="Form1" method="post" runat="server">
   <script language="javascript">
    var response = AJAXDemo.Resin.ServerSideAdd(100,99);
    alert(response.value);
   </script>
  </form>

同時可以改下如下,這樣會返回一個response對象,可以對程式異常進行處理
  <form id="Form1" method="post" runat="server">
   <script language="javascript">
    //var response = AJAXDemo.Resin.ServerSideAdd(100,99);
    //alert(response.value);
    AJAXDemo.Resin.ServerSideAdd(100,99,ServerSideAdd_CallBack);
    function ServerSideAdd_CallBack(response){
    if (response.error != null){
    alert(response.error);
    return;
    }
    alert(response.value);
    }
    
   </script>
  </form>

處理dataset的例子
服務端
  public DataSet GetDataSet()
  {
//   SqlHelper.ExecuteReader(ConfigurationSettings.AppSettings["connString"], "GetHostitalListByPymAndGroupid",querycode,groupid);
   
   DataSet myds = new DataSet();
   myds=SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings["connString"],CommandType.Text,"Select top 10 ypm,gg,cd,zxdw from zy_sys2_ypzdk");
   return myds;
  }
用戶端
   <script language="javascript">
    AJAXDemo.Resin.GetDataSet(GetDataSet_CallBack);
    function GetDataSet_CallBack(response){
     var ds = response.value;
     if(ds != null && typeof(ds) == "object" && ds.Tables != null){
      var s = new Array();
      s[s.length] = "<table border=1>";
      for(var i=0; i<ds.Tables[0].Rows.length; i++){
      s[s.length] = "<tr>";
      s[s.length] = "<td>" + ds.Tables[0].Rows[i].ypm + "</td>";
      s[s.length] = "<td>" + ds.Tables[0].Rows[i].gg + "</td>";
      s[s.length] = "</tr>";
     }
      s[s.length] = "</table>";
      alert(s.join(""));
     }
     else
     {
      alert("Error. [3001] " + response.error);
     }
    }    
   </script>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.