Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
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}
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
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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
My Ajax-Call:
Thank you, Nadine
This solution works for me:
Apparently, if I inherit from "UmbracoApiController" the Path always starts with /Umbraco/Api/
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
is working on a reply...