asp.net - Determining url for Ajax WebMethod (in Sitefinity) -
i'm trying figure out how determine baseurl should ajax webmethod post.
according sitefinity thread, baseurl path sitefinity project folder.
in case, path should along lines of:
"c:\inetpub\website\public" path not in same format "mywebform.aspx/webmethod"
this seems simple problem before go testing out, want make sure i'm doing right thing.
i'd appreciate suggestions , feedback.
thanks in advance.
function buttonclick(e) { e.preventdefault(); $.ajax({ type: "post", url: baseurl + "mywebform.aspx/webmethod", data: 1, contenttype: "application/json; charset=utf-8", datatype: "json", success: function() { alert('success'); }, error: function (msg) { alert('sorry, there error, please try again later'); } }); }
if have .aspx file @ root of sitefinitywebapp address can relative , base url "/". recommend putting folder "webmethods" baseurl "/webmethods". recommend using mvc controller myself or adding webapicontroller, you'll have add custom rout in bootstrapper, adding below global.asax. create cotnroller , can call /api/mycontroller/getsomestuff or /api/mycontroller/postsomestuff
protected void application_start(object sender, eventargs e) { bootstrapper.initialized += new eventhandler<executedeventargs> (onbootstrapperinitialized); } private static void onbootstrapperinitialized(object sender, telerik.sitefinity.data.executedeventargs e) { if (e.commandname == "bootstrapped") { registerroutes(routetable.routes); } } private static void registerroutes(routecollection routes) { routes.ignore("{resource}.axd/{*pathinfo}"); routes.maphttproute( name: "actionapi", routetemplate: "api/{controller}/{action}/{id}", defaults: new { id = routeparameter.optional } ); }
Comments
Post a Comment