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