该篇文章是我于2009年6月10日通过自己编写的工具,批量从位于在博客园的博客站点(http://chenxizhang.cnblogs.com)同步而来。文章中的图片地址仍然是链接到博客园的。特此说明! 陈希章原文地址:http://www.cnblogs.com/chenxizhang/archive/2009/05/28/1491250.html原文标题:jquery调用页面的方法 原文发表:2009/5/28 2:33:00 |
有些朋友问到,能不能在jquery代码中调用页面的服务器方法呢?答案是可以的
1. 首先,该方法必须是静态的,而且必须声明WebMethod
[WebMethod]
public static string PageHelloWorld()
{
return "Hello,world";
}
2. 调用代码与webservice的非常类似
///这个例子演示了如何调用页面的静态方法
function TestCallPageMethod() {
$.ajax({
type: "POST",
contentType: "application/json",
url: "mypage.aspx/PageHelloWorld",
data: "{}",
dataType: 'json',
success: function(result) {
alert(result.d);
}
});
}
作者:陈希章 出处:http://blog.csdn.net/chen_xizhang 本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |