Copied to clipboard

Flag this post as spam?

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


  • Nadine Fisch 159 posts 429 karma points
    Jun 04, 2018 @ 06:11
    Nadine Fisch
    0

    Ajax Call: Wrong Url Path

    Hi,

    I try to call a Controller Method via Ajax, but I am not able to use the correct path. Can anyone help me, please?

    The Method is in App_Code\Controllers\API\ExampleController.cs

    And in my Example.cs-file I have following code

    [AcceptVerbs("GET", "POST")]
             [HttpPost]
             [Route("/example/add/")]
             public String addExample(){
                    return "success";
             }
    

    My Ajax-Call:

    $.ajax({
        type: "POST",
        url: "/Controllers/API/example/add/",
        success: function (result) {
            alert(result);
        },
        error: function (result) {
            console.log(result);
        }
    });
    

    Thank you, Nadine

  • Nadine Fisch 159 posts 429 karma points
    Jun 04, 2018 @ 06:46
    Nadine Fisch
    101

    This solution works for me:

        url: "/Umbraco/Api/Example/addExample"
    

    Apparently, if I inherit from "UmbracoApiController" the Path always starts with /Umbraco/Api/

    /Umbraco/Api/{Controller}/{method}
    
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jun 04, 2018 @ 07:03
    Jan Skovgaard
    1

    Hi Nadine

    Happy to see you found the solution - This is also mentioned in the documentation here https://our.umbraco.org/documentation/Reference/Routing/WebApi/ if others should come across this post with the same issue as you.

    Have a nice day :-)

    /Jan

  • 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