在jquery代码中调用页面的服务器方法 [ 网站地图 ]

发表于:2009-12-28 浏览:158 作者: 来源:互联网

关键字:jquery,调用页面

描述:有些朋友问到,能不能在jquery代码中调用页面的服务器方法呢?答案是可以的   1.首先,该方法必须是静态的,而且必须声明WebMethod CODE[WebMethod]public static string PageHelloWorld(){   

有些朋友问到,能不能在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);
        }
    });
}


站长资讯网 做中国最丰富的资讯网站 沪ICP备05004089号