您的位置:首页 > 其它

AjaxPro 用法示例(参考)

2010-08-24 11:23 344 查看
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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: