小编Vis*_*wda的帖子

使用jQueryAjax"GET"调用WebMethod

我有一个ajax请求使用"POST"很好,但当使用"GET"它给我以下错误,

{"Message":"An attempt was made to call the method \u0027GetSomething\u0027 
using a GET      request, which is not allowed.","StackTrace":" at 
System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData 
methodData, HttpContext context)\r\n at 
System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, 
WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
Run Code Online (Sandbox Code Playgroud)

所以这是我的代码,在客户端,

function test() {
        $.ajax({
            url: "Default4.aspx/GetSomething",
            type: "GET",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: function (res) { debugger; alert(res.d); },
            error: function (res) { debugger; alert("error"); }
        });
    }
Run Code Online (Sandbox Code Playgroud)

在服务器端,

[WebMethod]
public static string GetSomething()
{
    return "got something";
}
Run Code Online (Sandbox Code Playgroud)

使用"GET"时我得到错误的任何原因??

jquery asp.net-ajax webmethod

18
推荐指数
1
解决办法
2万
查看次数

标签 统计

asp.net-ajax ×1

jquery ×1

webmethod ×1