• 您可以从www.schwarz-interactive.de 下载最新版的Ajax.NET Professional
  • 添加Ajax.NET Professional 的引用到您的工程
  • 配置Web.Config文件节
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      
    <system.web>
        
    <httpHandlers>
          
    <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
        
    </httpHandlers>

      []

      
    </system.web>
    </configuration>
  • 为服务器方法添加Ajax属性标记
    [AjaxPro.AjaxMethod]
    public DateTime GetServerTime()
    {
      
    return DateTime.Now;
    }
  • 如果想在客户端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;
        }

      }

    }

     

  • 使用下面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);
    }

     

posted on 2006-03-28 13:23  ideas  阅读(997)  评论(0编辑  收藏  举报