.net下的AjaxPro框架,简单入门

AjaxPro:
官方站点- http://www.ajaxpro.info/ ,如果你不下整个vs的组件,那下个AjaxPro.dll在项目中引用就可以了。
1.添加web.config
         < httpHandlers >
      
< add  verb ="POST,GET"  path ="AjaxPro/*.ashx"  type ="AjaxPro.AjaxHandlerFactory, AjaxPro" />
        
</ httpHandlers >
2.写一个要在client调用的server端方法
using  System;
using  System.Data;
using  System.Configuration;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;

namespace  MyAjax
{
    
/**//// <summary>
    
/// NumberOP 的摘要说明
    
/// </summary>

    public class NumberOP
    
{

        
public NumberOP()
        
{
        }


        [AjaxPro.AjaxMethod]]//要在client调用的必须使用这个attribute标明一下
        
public  int Add(int a, int b)
        
{
            
return a + b+100;
        }


        [AjaxPro.AjaxMethod]//要在client调用的必须使用这个attribute标明一下
        
public  string GetServerTime()
        
{
            
return DateTime.Now.ToShortTimeString();
        }

    }

}


3.在调用到的页面的page_load方法中注册这个类
using  System;
using  System.Data;
using  System.Configuration;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;
using  MyAjax;
public  partial  class  _Default : System.Web.UI.Page 
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        AjaxPro.Utility.RegisterTypeForAjax(
typeof(NumberOP));
    }

}

4.在html中写javascript调用server端的方法
<% @ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default"  %>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html  xmlns ="http://www.w3.org/1999/xhtml"   >
< head  runat ="server" >
    
< title > AjaxPro简单入门 </ title >
    
< script  type ="text/javascript" >
        
        
function getServerTime()
        
{
            
//调用server的MyAjax命名空间下的NumberOP类下的GetServerTime方法。
            //timeCallBack为客户端调用成功之后的回调方法
            MyAjax.NumberOP.GetServerTime(timeCallBack);
        }

        
        
//回调方法,result为server的返回值
        function timeCallBack(result)
        
{
            alert(result.value);
        }

        
        
        
function add()
        
{
            
//服务器端方法有参数,必须先写,回调方法写最后
            MyAjax.NumberOP.Add(4,6,addCallBack);
        }

        
function addCallBack(result)
        
{
            alert(result.value)
        }

    
</ script >
</ head >
< body >
    
< form  id ="form1"  runat ="server" >
        
< input  id ="Button1"  type ="button"  value ="getServerTime"  onclick ="getServerTime();"   />
        
< input  id ="Button2"  type ="button"  value ="add"  onclick ="add();"   />     
    
</ form >
</ body >
</ html >

5.整个例子 下载

转载于:https://www.cnblogs.com/oiea/archive/2007/11/06/951387.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值