Copied to clipboard

Flag this post as spam?

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


  • Manuel Ruiz 8 posts 28 karma points
    Oct 27, 2010 @ 16:41
    Manuel Ruiz
    0

    Umbraco calling Page WebMethod using Jquery Ajax

    I am working with Umbraco v 4.5.2

    I have a Custom Base Page

    public class BasePage : UmbracoDefault
        {       
            [WebMethod]
            public static string CallWebMethod()
            {
                return "Hello Umbraco";
            }
        }

     

    I updated the default.aspx page to whole pages inherit from my BasePage

    <%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="True" Inherits="Artc.Web.BasePage" trace="true" validateRequest="false" %>

    I have tried call the CallWebMethod() webmethod from a aspx page generated from umbraco

    The crecimiento-facebook.aspx is a page generated from umbraco.

    This page have the following code:

    <

     

    script src="/scripts/jquery.min.js" type="text/javascript"></script>

    <script type="text/javascript" language="javascript">
        
        
        function Call()
        {
            $.ajax
                (       
                    {          
                      type: "POST", 
                      url: "crecimiento-facebook.aspx/CallWebMethod",
                      data: "{}",
                      contentType: "application/json; charset=utf-8",
                      dataType: "json",
                      success: CallSuccess,
                      error: MostrarError
                    }
                 );
           
        }

    function CallSuccess(resultado)
        {        
            alert(resultado.d);
        }
        function MostrarError(error)
        { 
            alert(error.responseText);
        }


        </script>

    <input id="btnLlamadaAjax" type="button" value="Llamada Ajax"  onclick="Call()"/></div>

    When a click the btnLlamadaAjax button tha app show the error: No umbraco document matches the url 'http://www.artc.pe/es/home/noticias/crecimiento-facebook.aspx/call'

    When a use a custom aspx page, this page is in th custompages Folder

    <add key="umbracoReservedPaths" value="~/umbraco,~/install,~/custompages/" />

    In this case the ajax call is working. The problem is when the page is a page generated from umbraco.

    I know that I can use a Web Services (ASMX) to call a WebMethod or Umbraco /Base , but i would like call a Page WebMethod.

    Is it possible?

     

    Thanks

    Regards From Lima - Peru

    ERROR:

    <html><body><h1>Page not found</h1><h3>No umbraco document matches the url 'http://www.artc.pe/es/home/noticias/crecimiento-facebook.aspx/call'</h3><p>umbraco tried this to match it using this xpath query'/root/* [@urlName = "es"]/* [@urlName = "home"]/* [@urlName = "noticias"]/* [@urlName = "crecimiento-facebook"]/* [@urlName = "call"]')</p><p>This page can be replaced with a custom 404 page by adding the id of the umbraco document to show as 404 page in the /config/umbracoSettings.config file. Just add the id to the '/settings/content/errors/error404' element.</p><p>For more information, visit <a href="http://umbraco.org/redir/custom-404">information about custom 404</a> on the umbraco website.</p><p style="border-top: 1px solid #ccc; padding-top: 10px"><small>This page is intentionally left ugly ;-)</small></p></body></html>

     

  • Matt Brailsford 2958 posts 15629 karma points MVP 7x c-trib
    Oct 27, 2010 @ 17:10
  • Manuel Ruiz 8 posts 28 karma points
    Oct 27, 2010 @ 17:45
    Manuel Ruiz
    0

    Hi Matt

    Thanks for your answer

    I know that I can use Umbraco /Base , but i would like call a Page WebMethod, because a think Umbraco /Base use reflection to call the WebMethod, and it is slower than use the native Jquery Ajax call. Right?

    Please, Let me know is a i am wrong.

                      Manuel

  • Aaron Powell 1708 posts 3044 karma points c-trib
    Oct 27, 2010 @ 23:06
    Aaron Powell
    0

    If you're worried about the performance of using reflection then you've got larger problems in your overall site :P.

    I haven't tried WebMethods for years for several reasons (which I wont go into here) but when I tried last you couldn't do it because of the way the Umbraco routing engine works.

    You're better off using Base or WebServces

  • Petr Snobelt 923 posts 1534 karma points
    Oct 28, 2010 @ 00:07
    Petr Snobelt
    0

    +1 for WebService.

    In theory it should be possible to add webmethod function into template into script with runat="server tag.

  • Aaron Powell 1708 posts 3044 karma points c-trib
    Oct 28, 2010 @ 00:52
    Aaron Powell
    0

    Theory != practice :P

    WebMethod is really just a work around to turn a page into a pesudo-web service but the problem is that the Umbraco routing engine sees the path and thinks that you should be going to a page.

    I've never seen a scenario where a WebMethod was the best choice, it always seemed like implementing something in the wrong place.

  • Manuel Ruiz 8 posts 28 karma points
    Nov 03, 2010 @ 17:00
    Manuel Ruiz
    0

    Hi

    Thanks for yours answers

    Now I am using Base .

    I am passing params using url. It is working.

    I tried pass params using:

    data: "{'nombre':'" + nombre + "','apellidos': '" + apellidos +"' ,'email': '" + email + "','telefono': '" + telefono + "','mensaje': '" + mensaje + "'}",

    But didn't work. Why?. I would like use the data parms

     $.ajax
                        (       
                            {          
                              type: "POST", 
                              url: "/Base/ArtcBase/SendEmail/" + nombre + "/" + apellidos + "/" + email + "/" + telefono + "/" + mensaje + ".aspx",
                              //data: "{'nombre':'" + nombre + "','apellidos': '" + apellidos +"' ,'email': '" + email + "','telefono': '" + telefono + "','mensaje': '" + mensaje + "'}",
                              data: "{}",
                              contentType: "application/json; charset=utf-8",
                              dataType: "json",
                              success: EnviarSuccess,
                              error: MostrarError
                            }
                         );

     

     

     

     

    public

     

    static string SendEmail(string nombre, string apellidos, string email, string telefono, string  mensaje)

    {

    return true;

    }

     

     

    Regards

                          Manuel

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies