伊图教程网[www.etoow.com]
http://www.etoow.com/html/2007-08/1186821583.html
//调用方法:类名.方法名 (参数为指定一个回调函数)
myLoad.GetServerTime(callback);
}
function callback(res) //回调函数,显示结果
{
alert(res.value);
}
</script>
</form>
</body>
</html>
注:javascript代码放在form内结束处,确保可以访问AjaxPro对象,否则提示AjaxPro未定义;因为在服务端page_load输出js到页面后才到找到AjaxPro对象;且javascript的defer="defer",页面加载时先不执行此代码。
服务端代码:
public partial class myLoad : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(myLoad)); //注册ajaxPro,括号中的参数是当前的类名
}
[AjaxPro.AjaxMethod] //申明是ajaxPro方法
public string GetServerTime()
{
System.Threading.Thread.Sleep(2000);
return DateTime.Now.ToString();
}
}
使用AjaxPro实现Ajax效果
'http://www.etoow.com/html/2007-08/1186821583.html