AjaxPro2在Asp.net中的基本用法
        【摘要】  AjaxPro2在Asp.net中的基本用法 
1.      引用ajaxPro2.dll到你的工程中。 
2.      在Web.config中添加配置 
 
 <
 httpHandlers
 >
  
   &nb...
    
    
    
    AjaxPro2在Asp.net中的基本用法
1. 引用ajaxPro2.dll到你的工程中。
2. 在Web.config中添加配置
 < httpHandlers >
 < httpHandlers > 
  < add  path ="ajaxpro/*.ashx"  verb ="POST,GET"  type ="AjaxPro.AjaxHandlerFactory, AjaxPro.2"   />
        < add  path ="ajaxpro/*.ashx"  verb ="POST,GET"  type ="AjaxPro.AjaxHandlerFactory, AjaxPro.2"   /> 
  </ httpHandlers >
    </ httpHandlers > 
  
 
3. 在程序中注冊Ajax
 protected  void Page_Load( object sender, EventArgs e)
 protected  void Page_Load( object sender, EventArgs e) 
  {
     { AjaxPro.Utility.RegisterTypeForAjax(typeof(filejob_DCFCS01));
        AjaxPro.Utility.RegisterTypeForAjax(typeof(filejob_DCFCS01)); }
    } 
  ……
…… 
  [AjaxPro.AjaxMethod]
[AjaxPro.AjaxMethod] 
  public  string[] GetOldInfo( string No)
     public  string[] GetOldInfo( string No) 
  {
     { String [] strret=new string[5];
            String [] strret=new string[5]; ……
            …… Return strret;
            Return strret; }
        } 
  
 
4. 在客戶端的調用
 <asp:TextBox ID="tbxODANo" runat="server" CssClass="Input" MaxLength="7" Width="134px" οnchange=”getInfo( this);”></asp:TextBox>
<asp:TextBox ID="tbxODANo" runat="server" CssClass="Input" MaxLength="7" Width="134px" οnchange=”getInfo( this);”></asp:TextBox> 
  <script type=”text/javascript”>
<script type=”text/javascript”> 
  Function getInfo(oda)
Function getInfo(oda) 
  {
 { Var no=oda.value;
        Var no=oda.value; filejob_DCFCS01. GetOldInfo(no,callback);//異步方法
        filejob_DCFCS01. GetOldInfo(no,callback);//異步方法 }
} 
  Function callback(res)
Function callback(res) 
  {
 { If(res.error)
     If(res.error) Alert(“錯誤”);
        Alert(“錯誤”); Else
     Else {
    { Alert(Res.value[0]);
    Alert(Res.value[0]); }
} }
} 
  
 
可以把Ajax要操作的方法放到一個Ajax操作類里
 Public  class AjaxMethod
Public  class AjaxMethod 
  
 
  {
 {
 [Ajax.AjaxMethod]
  [Ajax.AjaxMethod] public static string[] GetOldInfo(string No)
  public static string[] GetOldInfo(string No) {
    { String [] strret=new string[5];
                  String [] strret=new string[5]; ……
                  …… Return strret;
                  Return strret; }
          } }
} 
  
 
  
 
在調用時要注冊Ajax:
AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxMethod));
5. AjaxPro方法返回DataSet
只能在同步ajax時才能返回DataSet 類型
 Public  class AjaxMethod
Public  class AjaxMethod 
  {
 { [Ajax.AjaxMethod]
[Ajax.AjaxMethod] public static DataSet GetOldInfo(string No)
 public static DataSet GetOldInfo(string No) {
{ ……
     …… Return ds;
   Return ds; }
} }
} 
  
 
在客戶端取DataSet數據:
 Function getInfo()
Function getInfo() 
  {
 { Var res= AjaxMethod. GetOldInfo(oda.value).value; //同步調用
 Var res= AjaxMethod. GetOldInfo(oda.value).value; //同步調用 If(ds!=null)
 If(ds!=null) {
{ Var dt=ds.Tables[0];
  Var dt=ds.Tables[0]; Var rows=dt.Rows.length;
Var rows=dt.Rows.length; For(var i=0;i<rows;i++)
For(var i=0;i<rows;i++) {
{ Document.write(dt.Rows[i][dt.Columns[0].name]);
 Document.write(dt.Rows[i][dt.Columns[0].name]); }
} }
} }
} 
  
  
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/54880668
        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
            cloudbbs@huaweicloud.com
        
        
        
        
        
        
        - 点赞
- 收藏
- 关注作者
 
             
           
评论(0)