首页 新闻 会员 周边

Jquery调用ASP.NET的webservice

0
悬赏园豆:5 [已关闭问题] 关闭于 2012-10-19 15:12

TestWebService.asmx:

    /// <summary>
    /// TestWebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
     [System.Web.Script.Services.ScriptService]
    public class TestWebService : System.Web.Services.WebService
    {
        [WebMethod]
        public  int TestNoParams()
        {
            return 0;
        }

        [WebMethod]
        public  string TestWithParams(string a, int b)
        {
            return a + b.ToString();
        }
    }

aspx: 

       function PageMethod(fn, paramArray, successFn, errorFn) {
            var pagePath = window.location.pathname;
            var paramList = '';
            if (paramArray.length > 0) {
                for (var i = 0; i < paramArray.length; i += 2) {
                    if (paramList.length > 0) paramList += ',';
                    paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"';
                }
            }
            paramList = '{' + paramList + '}';
            $.ajax({
                type: "POST",
                url: "TestWebService.asmx" + "/" + fn,
                contentType: "application/json;charset=utf-8",
                data: paramList,
                dataType: "json",
                success: successFn,
                error: errorFn
            });
        }
        PageMethod("TestWithParams", ["a", "value", "b", 2], AjaxSucceeded, AjaxFailed);
        function AjaxSucceeded() {
            alert('ok');
        }
        function AjaxFailed() {
            alert("error");
        }

问题补充:

不知道为什么不调用TestWebService里面的方法

xyq_雨晴的主页 xyq_雨晴 | 初学一级 | 园豆:159
提问于:2012-10-19 13:30
< >
分享
所有回答(1)
0

不想用这个

我欲成魔 | 园豆:216 (菜鸟二级) | 2012-10-19 14:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册