AjaxPro2的使用说明

配置:

1、在web项目中增加对AjaxPro.2.dll的引用

2、在web.config中的System.Web配置节下增加如下HttpHandler:

<httpHandlers>      <add verb="*" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>    </httpHandlers>

3、每个web页面都要继承LimitedPageBase或者CommPageBase.

使用说明:

1、UI的代码如下:

  
    
< input id ="txtContent" type ="text" value ="my text here!" />
< input type ="button" id ="ajaxBtn" value ="daksjfkda" />
< script type ="text/javascript" >
var p = null ;
$(
" #ajaxBtn " ).bind( ' click ' , function () {

// 同步返回了一个字符串
p = ASP.default_aspx.HelloWorld($( ' #txtContent ' )[ 0 ].value);
alert(p.value);

// 同步返回了一个对象
p = ASP.default_aspx.GetMyData();
alert(p.value.Name
+ p.value.Pwd);

// 异步返回了一个对象
ASP.default_aspx.GetMyData(callbackTest1);
$(
' #txtContent ' ).val( " waiting " );

});

function callbackTest1(res) {
alert(
" 返回 " );
alert(res.value.Name
+ res.value.Pwd);
}
</ script >

2、该页面后台代码为:

  
    
public static int RequestTimes = 0 ;
[AjaxPro.AjaxMethod]
public string HelloWorld( string msg)
{
RequestTimes
++ ;
return " Come from HelloWorld function: " + msg;
}

[AjaxPro.AjaxMethod]
public MyData GetMyData()
{
RequestTimes
++ ;
return new MyData();
}

3、上面说的都是在页面的后台代码中定义WebMethod,如果有些WebMethod是公用的,请定义在CommAjaxHelper中。

4、所有的页面必须继承CommPageBase或者LimitedPageBase。

你可能感兴趣的:(Ajax)