AjaxPro入门使用方法

AjaxPro的官网是http://ajaxpro.info,你可以下载到最新的AjaxPro组件。

如果你用的是.NET2.0,你只需要把AjaxPro.2.dll放入应用程序的bin文件夹中,引用下这个DLL就好了,这里需要注意下一般下载解压缩后里面会有 AjaxPro.DLL 和AjaxPro.2.DLL。使用.Net 2.0一直JavaScript报错说未定义‘命名空间和类’,换成AjaxPro.2.Dll就好了。

下面是使用的步骤(别忘了先引用DLL):

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;
}

3、在.NET方法中向客户端注册javascript,用以javascript使用

以下为引用的内容:

namespace MyDemo
{
public class _Default
{
    protected void Page_Load(object sender, EventArgs e)
    {
      AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
    }

    [AjaxPro.AjaxMethod]
    public DateTime GetServerTime()
    {
      return DateTime.Now;
    }
}
}

4、在客户端用javascript调用服务器端的方法,语法也很简单

以下为引用的内容:
function getServerTime()
{
MyDemo._Default.GetServerTime(getServerTime_callback); // asynchronous call
}

// This method will be called after the method has been executed
// and the result has been sent to the client.

function getServerTime_callback(res)
{
alert(res.value);
}

就这样,简单的几步,就已经完成了。在客户端用javascript异步调用服务器端的C#方法,并可以得到服务器端的返回值。

转载于:https://www.cnblogs.com/chenshengtai/archive/2011/07/20/2111406.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值