使用Jquery ajax post方法时出现内部服务器错误

时间:2014-01-29 13:30:52

标签: jquery json

我有一个带有多选复选框的自动选择下拉列表的以下javascript代码:

function f() {

    var data;
    $("#csrch").attr('value', '');
    $.ajax
    ({
        //calling aspx web method
        url: 'drpCtrl.aspx/CustomerFilter',
        type: 'POST',
        //since webmethod does not have parameter given data as empty
        data: '',
        datatype: 'json',
        contentType: 'application/json',
        mimeType: 'application/json',
        error: function (jqxhr, status, error) {

            alert(error)
        }
    });
}

从后面的代码中调用此Web方法

[WebMethod]
public string CustomerFilter()
{
    string result = "";
    //retrieving customer list from database where it returns as json format
    result = Convert.ToString(objSLA.ExecuteScalar       (CommandType.StoredProcedure, "Usp_Get_Customer_Test"));
    //returning string format
    return result;
}

Webmethod CustomerFilter()没有调用,我收到内部服务器错误。请帮助上面的编码结果出错:

{
   "uin":{
      "customer":[
         {
            "i":"1",
            "n":"Ahold Financial Services"
         },
         {
            "i":"2",
            "n":"ALM"
         },
         {
            "i":"3",
            "n":"Associated Global Systems, Inc."
         }
      ]
   }
}

1 个答案:

答案 0 :(得分:0)

尝试在您的Codebehind方法中添加static

[WebMethod]
    public static string CustomerFilter()
    {
        string result = "";
        //retrieving customer list from database where it returns as json format
        result = Convert.ToString(objSLA.ExecuteScalar       (CommandType.StoredProcedure, "Usp_Get_Customer_Test"));
        //returning string format
        return result;
    }