我似乎無法使用POST和GET從Ajax調用Web服務方法。在ASMX Web服務中使用POST和GET Ajax調用相同的WebMethod
最初只有POST將工作和GET會導致此錯誤:
{"Message":"An attempt was made to call the method \u0027getData\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"}
我固定,通過增加該屬性:[ScriptMethod(UseHttpGet=true)]
但現在得到的原因這個錯誤:
{"Message":"An attempt was made to call the method \u0027getData\u0027 using a POST 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"}
因此,它是確實,您只能使用POST或GET,而不能同時使用Ajax?有誰知道爲什麼會發生這種情況,或者是否有解決方法?
在此先感謝!
我理解的風險,但GET請求都是爲了與JSONP使用。 – celticpride 2010-01-20 14:41:14