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
I'm trying to call this method
[RestExtension("AjaxExtensions")] public class AjaxExtensions { [RestExtensionMethod(ReturnXml = false)] public static void HelloWorld() { string foo = "bar"; } } with this Ajax Post call $.ajax({ url: '/base/AjaxExtensions/HelloWorld', type: 'POST', success: function (data) { } }); Just to see if i hit the method but nothing happens. The AjaxExtension file is placed in App_Code->Folder->Another folder. I'm running Umbraco version 6.1.6
[RestExtension("AjaxExtensions")] public class AjaxExtensions { [RestExtensionMethod(ReturnXml = false)] public static void HelloWorld() { string foo = "bar"; } }
with this Ajax Post call
$.ajax({ url: '/base/AjaxExtensions/HelloWorld', type: 'POST', success: function (data) { } });
Just to see if i hit the method but nothing happens.
The AjaxExtension file is placed in App_Code->Folder->Another folder.
I'm running Umbraco version 6.1.6
Hi Jan,
Have you tried using a UmbracoApiController (based on .net WebApi) instead? It pretty much replaces the the RestExtensions functionality.
You can find information on UmbracoWebApiController here: http://our.umbraco.org/documentation/Reference/WebApi/
It's pretty nifty. Please mark this as the answer if it solves your problem. :)
Jamie
EDIT: Here's a rough example
public class YourApiController : UmbracoApiController { public string HelloWorld() { return "It's pretty nifty :)"; } }
And your JS:
$.ajax({ url: '/Umbraco/Api/YourApi/HelloWorld', type: 'POST' }).done: function (result) { alert(result); });
This is using jQuery's Done/Fail/Always as Success is deprecated. You can find out about this here.
Your suggestion worked like a charm, thx.
But.....
Now i'm trying make a POST with parameters and it doesn't work
Here's my code
$.ajax({
url: '/Umbraco/Api/Helper/AddRequisitionNumberToOrder/', data: { reqNumber: comment, orderGuid: og}, type: 'POST', success: function (data) { alert(data); } });
public class HelperController: UmbracoApiController { public string AddRequisitionNumberToOrder(string reqNumber, string orderGuid) { var orderG = new Guid(orderGuid); var order = PurchaseOrder.FirstOrDefault(x => x.OrderGuid == orderG); if (order != null) { order["Rekvisitionsnummer"] = reqNumber; order.Save(); return "Rekvisitionsnummer er gemt"; } return "Det indtastede kunne ikke gemmes. Prøv venligst igen"; }
The API method isn't hit.
It has to be a syntax problem, but i can't find it.
It could be the trailing slash on the end of your URL you're pointing to. Upon changing that I was able to hit the API method.
After that, I got issues posting values to the controller. Which might be related to this:
http://encosia.com/using-jquery-to-post-frombody-parameters-to-web-api/
You might also find this useful too:
http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api
I could be googling the wrong thing here. So feel free to correct me if I am. I might be going off track :/
When I've used WebAPI recently, I used a GET API call, but that was suitable for my solution. It may not be the case here.
I hope some of this helps. I'd think about taking the trailing slash off the URL first and see if that gets you any closer to a working solution.
Thanks, Jamie
is working on a reply...
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.
Continue discussion
Can't call RestExtension method
I'm trying to call this method
Hi Jan,
Have you tried using a UmbracoApiController (based on .net WebApi) instead? It pretty much replaces the the RestExtensions functionality.
You can find information on UmbracoWebApiController here: http://our.umbraco.org/documentation/Reference/WebApi/
It's pretty nifty. Please mark this as the answer if it solves your problem. :)
Jamie
EDIT: Here's a rough example
And your JS:
This is using jQuery's Done/Fail/Always as Success is deprecated. You can find out about this here.
Your suggestion worked like a charm, thx.
But.....
Now i'm trying make a POST with parameters and it doesn't work
Here's my code
$.ajax({
The API method isn't hit.
It has to be a syntax problem, but i can't find it.
It could be the trailing slash on the end of your URL you're pointing to. Upon changing that I was able to hit the API method.
After that, I got issues posting values to the controller. Which might be related to this:
http://encosia.com/using-jquery-to-post-frombody-parameters-to-web-api/
You might also find this useful too:
http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api
I could be googling the wrong thing here. So feel free to correct me if I am. I might be going off track :/
When I've used WebAPI recently, I used a GET API call, but that was suitable for my solution. It may not be the case here.
I hope some of this helps. I'd think about taking the trailing slash off the URL first and see if that gets you any closer to a working solution.
Thanks,
Jamie
is working on a reply...
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.