Ho una richiesta Ajax che funziona bene con "POST", ma quando viene utilizzato "GET" mi dà il seguente errore,Chiamare un WebMethod utilizzando 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"}
ecco il mio codice, su Dal lato client,
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"); }
});
}
sul lato server,
[WebMethod]
public static string GetSomething()
{
return "got something";
}
alcuna ragione per cui sto ottenendo l'errore quando viene utilizzato "GET" ??
Il "post" funziona? – dhinesh