本文介绍了调用使用jQueryAjax&QUOT一个WebMethod; GET"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Ajax请求效果很好使用POST,而是用GET时,它给了我下面的错误,
i have a ajax request which works well using "POST" but when used "GET" it gives me the following error,
{"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"}
所以这里是我的code,在客户端,
so here is my code, on the client side,
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"); }
});
}
在服务器端,
[WebMethod]
public static string GetSomething()
{
return "got something";
}
任何理由使用GET??时为什么我收到错误
any reason why i am getting error when used "GET" ??
推荐答案
如果您想要调用用得到它,你需要添加:
If you want to invoke it using GET, you need to add:
[WebMethod]
[ScriptMethod(UseHttpGet=true)]
....
这篇关于调用使用jQueryAjax&QUOT一个WebMethod; GET"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!