chenxizhang

jquery调用页面的方法

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

分类:

技术点:

相关文章:

  • 2021-05-04
  • 2021-09-16
  • 2021-12-06
  • 2021-09-14
  • 2021-11-04
  • 2021-08-27
猜你喜欢
  • 2021-11-29
  • 2021-08-27
  • 2021-12-19
  • 2021-11-22
  • 2021-09-07
  • 2021-12-20
  • 2021-11-07
相关资源
相似解决方案