Copied to clipboard

Flag this post as spam?

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


  • Hussain 1 post 72 karma points
    Aug 06, 2016 @ 02:31
    Hussain
    1

    Calling a Webmethod using Ajax

    Hi,

    I'm tring to call a aspx Webmethod using Ajax, but its not hitting the method rather the url says:

    Page not found

    No umbraco document matches the url '/Page.aspx/MethodName'.

    This page can be replaced with a custom 404. Check the documentation for "custom 404".

    This page is intentionally left ugly ;-)

    My ajax code:

           $.ajax({
                type: "POST",
                url: 'Page.aspx/MethodName',
                contentType: "application/json; charset=utf-8",
                data: '{ "Name": "name" }',
                dataType: "json",
                success: function (response) {
                    alert(response);
                }
            });
    

    Method code:

    [System.Web.Services.WebMethod]
    public static string MethodName(string Name)
    {
        return Name;
    }
    
  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Aug 08, 2016 @ 08:56
    Alex Skrypnyk
    0

    Hi Hussain,

    Welcome to our forum!

    You don't need to use .aspx pages and web page methods for getting data from your site when you are using Umbraco.

    You have to create webApi or Surface controller and get data from there.

    Read more abour webapi: https://our.umbraco.org/documentation/reference/routing/webapi/

    Example of GET method:

    public class ProductsController : UmbracoApiController
    {       
        public IEnumerable<string> GetAllProducts()
        {
            return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" };
        }
    }
    

    Example of url:

    ~/Umbraco/Api/Products/GetAllProducts
    

    Thanks,

    Alex

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Aug 11, 2016 @ 12:02
    Alex Skrypnyk
    0

    Hi Hussain,

    Did you solve your problem?

    Please, answer something, maybe we will find solution together!

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft