c# - POST Request failing due to GET request not allowed -
i have webmethod in code behind i'm calling via ajax. method works when using request i'd prefer utilize post , i'd know why doesn't work and/or i'm doing wrong.
javascript
$(document).ready(function () { $.ajax({ url: "default.aspx/helloworld", method: "post", data: "{}", contenttype: "application/json; charset=utf-8", datatype: "json", success: function (data) { $("#test1").html(data.d); }, error: function (err) { $("#erroutput").text("error: " + err.responsetext); } }); }); c#
[webmethod] [scriptmethod(usehttpget=false)] public static string helloworld() { homecoming "hello world!"; } error
message: "an effort made phone call method \u0027helloworld\u0027 using request, not allowed.", stacktrace: "at system.web.script.services.resthandler.getrawparams(webservicemethoddata methoddata, httpcontext context)\r\n @ system.web.script.services.resthandler.executewebservicecall(httpcontext context, webservicemethoddata methoddata)", exceptiontype:"system.invalidoperationexception"
looking @ jquery documentation think you're using wrong property. suspect this:
method: "post" should be
type: "post" method feels more sensible name me too, there go...
(disclaimer: i've never used jquery myself... reply purely based on docs.)
c# jquery ajax
No comments:
Post a Comment