L'appel d'une WebMethod à l'aide de jQueryAjax “GET”

j'ai une requête ajax qui fonctionne bien en utilisant "POST" mais lorsqu'il est utilisé "GET" il me donne l'erreur suivante,

{"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"}

voici donc mon code, sur le côté 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"); }
        });
    }

sur le côté serveur,

[WebMethod]
public static string GetSomething()
{
    return "got something";
}

aucune raison pourquoi j'obtiens erreur de "GET" ??

  • Est le "poste de travail"?
InformationsquelleAutor Vishal Gowda | 2012-05-25