小编Dan*_*nas的帖子

ASP.NET使用jQuery AJAX调用WebMethod"401(未经授权)"

被困这几个小时了

{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}
Run Code Online (Sandbox Code Playgroud)

我试图在我的ASP.Net Webform中调用这个WebMethod

[WebMethod]
public static string GetClients(string searchTerm, int pageIndex)
{
    string query = "[GetClients_Pager]";
    SqlCommand cmd = new SqlCommand(query);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@SearchTerm", searchTerm);
    cmd.Parameters.AddWithValue("@PageIndex", pageIndex);
    cmd.Parameters.AddWithValue("@PageSize", PageSize);
    cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
    return GetData(cmd, pageIndex).GetXml();
}
Run Code Online (Sandbox Code Playgroud)

从这个jquery.ajax

function GetClients(pageIndex) {
    $.ajax({
        type: "POST",
        url: "ConsultaPedidos.aspx/GetClients",
        data: '{searchTerm: "' + SearchTerm() + '", pageIndex: ' + pageIndex + '}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccess,
        failure: function (response) {
            alert(response.d);
            },
            error: function (response) { …
Run Code Online (Sandbox Code Playgroud)

c# asp.net ajax jquery webmethod

44
推荐指数
4
解决办法
6万
查看次数

标签 统计

ajax ×1

asp.net ×1

c# ×1

jquery ×1

webmethod ×1