mam żądania ajax, który działa dobrze przy użyciu „post”, ale gdy używany „GET” to daje mi następujący błąd,Wywołanie WebMethod przy użyciu jQueryAjax „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"}
więc tutaj jest mój kod, na po stronie klienta,
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"); }
});
}
po stronie serwera,
[WebMethod]
public static string GetSomething()
{
return "got something";
}
jakikolwiek powód, dlaczego otrzymuję błąd, gdy używane "GET" ??
Czy "post" działa? – dhinesh