首页 > Web开发 > 详细

jquery调用页面的方法

时间:2014-11-28 13:56:46      阅读:202      评论:0      收藏:0      [点我收藏+]

本文转载:http://www.cnblogs.com/chenxizhang/archive/2009/05/28/1491250.html

有些朋友问到,能不能在jquery代码中调用后台cs页面的服务器方法呢?答案是可以的

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

jquery调用页面的方法

原文:http://www.cnblogs.com/zfanlong1314/p/4128176.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!