Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • paulus 1 post 21 karma points
    Apr 25, 2013 @ 17:20
    paulus
    0

    Using Ajax in Umbraco for Noob Dev

    Hi, can anybody help me? I'm usually develop website using PHP. And I'm really new to this ASP.NET. I have no knowledge about ASP. And I have ASP project which I develop using umbraco CMS. Can anyone guide me how to using ajax here?

    Before now, I only doing umbraco with its document type and XSLT. but at this point I need to use ajax here. In PHP I just need to make a PHP file and call it with ajax. I already googled up, and many people say about /base. I really dont understand about this base. But what I get is, I need to make .aspx file and call it with jquery ajax (remind me if I'm wrong), adn thas /base is the simple .aspx file.

    I read the example and get the code bellow. But again, I'm really noob in this ASP. I open up VS 2010, and I choose MVC c# project (is that correct)? and Then I see my project tree on my right hand panel. But I dont know where should I paste the code.

    Can anyone guide me how to develop aspx file? and I also read after compiling the file I need to copy the dll file.
    I'm very gratefull if you explain this step also.

     

    Thank you very much

    namespace BaseTest {
       
    [RestExtension("myAlias")]
       
    public class TestClass {
           
    [RestExtensionMethod()]
           
    public static string Hello() {
               
    return "Hello World";
           
    }
       
    }
    }
  • lothar 25 posts 99 karma points
    May 29, 2013 @ 23:09
    lothar
    0

    Maybe a late reply but here it goes anyways

    For creating base extensions you only need a dll so a Class Library project should do it.

    Next step is to make a class that has the appropriate attributes like you implemented

    namespace BaseTest{
       
    [RestExtension("myAlias")]
        public class TestClass{
            [RestExtensionMethod(returnXml = false)]

           
    public static string Hello(){
               
    return"Hello World";
           
    }
       
    }
    }

    You then build your solution and put the dll into your umbraco bin folder

    No need to do anything else but call the url.

    To call a method from base it goes like this

    http://<yourdomain>/base/<RestExtensionAlias>/<methodname>/

    For the method Hello it looks like this:

    http://domain/base/myAlias/Hello/

    Note: the alias & method are case sensitive

    Which will return xml:

    <value>Hello World</value>

    If you don't want xml set the parameter 'returnXml' to false

    namespace BaseTest{
       
    [RestExtension("myAlias")]
       
    public class TestClass{
            [RestExtensionMethod(returnXml = false)]

           
    public static string Hello(){
               
    return "Hello World";
           
    }
       
    }
    }

    Which then will return:

    Hello World

     

    You can also pass parameters to a method:

    namespace BaseTest{
       
    [RestExtension("myAlias")]
       
    public class TestClass{
            [RestExtensionMethod(returnXml = false)]
            public static string Hello(string name) {
                return "Hello " + name;
            }
       
    }
    }

    The url looks then like this: http://domain/base/myAlias/Hello/paulus/ which gives:

    Hello paulus

     

    To use this with $.ajax you just set the url parameter to the url above

    Thats the basics to use base

    Hope this helps :)

Please Sign in or register to post replies

Write your reply to:

Draft