ajax调用web方法不起作用

时间:2013-05-27 06:33:41

标签: c# asp.net ajax webmethod

我有这个ajax电话

   function findPICKey() {
        filter = document.getElementById('MainCT_dtvJobVac_PIC').value;
        $.ajax({
            type: 'POST',
            contentType: 'application/json;',
            data: "{listuser:" + JSON.stringify(resultarr) + ", keyword:'" + JSON.strigify(filter)+ "'}",
            dataType: 'json',
            url: 'SvcAutoComplete.asmx/GetPICKey',
            success: function (result) {
                result = JSON.parse(result.d);
                document.getElementById('<%= dtvJobVac.FindControl("PICKey").ClientID %>').value = result;

           },
               error: function (result) {
                   alert("error getting pic key");
               }
           })
    }

网络方法

   [WebMethod]
        public string GetPICKey(List<BO> listuser, string keyword)
        {
            //List<BO> ListObj = new List<BO>();
            //ListObj = (List<BO>)Session["ListPIC"];
            //ListObj = listuser;
            //string key = string.Empty;

            //for (int i = 0; i < ListObj.Count; i++)
            //{
            //    if(ListObj[i].label == keyword)
            //    {
            //        key = ListObj[i].value;
            //        break;
            //    }
            //}

            //return key;
            return "";
        }

由于某些原因我的网络方法没有被调用,我提出了一个断点,但它没有触发,我在这里做错了什么? btw resultarr是一个对象。

3 个答案:

答案 0 :(得分:0)

只是检查,但你知道你的第二个字符串拼写错了吗? “JSON.stringify”:)

答案 1 :(得分:0)

我认为问题在于

 data: "{listuser:" + JSON.stringify(resultarr) + ", keyword:'" + JSON.strigify(filter)+ "'}",
it should be 

 data: {listuser:"+ JSON.stringify(resultarr) +" , keyword:" + JSON.strigify(filter)+ "},

or
data: {listuser:JSON.stringify(resultarr) , keyword:JSON.strigify(filter)},

答案 2 :(得分:0)

如果你从localhost调用webservice,你应该检查url

eq:

http://localhost/HenryChunag/SvcAutoComplete.asmx

网址应为:

url: '/HenryChunag/SvcAutoComplete.asmx/GetPICKey'
相关问题