ajax - HttpRoutes - how do they work? -


i´m struggling urls ajax-reader/json. each time think understand it, seems haven´t. please, can explain logic behind this???

i got controller:

 public class servicecontroller : dnnapicontroller     {         [allowanonymous]         [httpget]         public httpresponsemessage getallitems(int moduleid)         {             myprojectcontroller controller = new myprojectcontroller();             ienumerable<iteminfo> items = controller.getallitems(moduleid);             return request.createresponse(httpstatuscode.ok, items);         }     } 

i got routemapper:

public class routemapper : iserviceroutemapper     {         public void registerroutes(imaproute maproutemanager)         {             maproutemanager.maphttproute("myproject",                                          "default",                                          "{controller}/{action}",                                          new[] { "mycompany.myproject.services" });         }     } 

at url can read data $.ajax() , url showing me data in browser?

thanx in advance!

asle :)

this how (note: work dnn6.2 , above);

  1. in view.ascx.cs add

    protected override void oninit(eventargs e) {     base.oninit(e);     servicesframework.instance.requestajaxscriptsupport();     servicesframework.instance.requestajaxantiforgerysupport();     jquery.requestdnnpluginsregistration(); } 

    this ensures jquery , required dnn ajax plugins added.

  2. initiate services framework jquery plugin in view.ascx inside javascript script tags (s.o. wouldn't allow me include them)

var modid = <%=moduleid %>;     var sf = $.servicesframework(modid); 
  1. now in separate javascript file or in view.ascx control add ajax function
function getallitems(){   $.ajax({   type:"get",   url:sf.getserviceroot("myproject")+"service/getallitems",   beforesend:sf.setmoduleheaders,   data:{moduleid:modid},   cache:false   }).done(function(data){     alert("success!");   }).fail(function(){     alert("crashed!");   }).always(function(){     //something want done whether passed or failed     //like hide progress bar, ajax spinner etc.   }); } 

the dnn jquery plugin build url similar (note: 142 illustration purpose , replace actual module id)

/desktopmodules/myproject/api/service/getallitems?moduleid=142


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -