"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Marked as answer by JustPlaneCrazy on Jun 11, 2012 02:31 PM
JustPlaneCra...
Member
4 Points
12 Posts
Ajax not posting to custom action
Jun 08, 2012 03:43 PM|LINK
I have the following JS code:
<script type="text/javascript"> $(function () { $("#addPayment").submit(function (e) { e.preventDefault(); $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "http://localhost:65396/api/payment/charge", data: $('#addPayment').serialize(), dataType: "json", success: function (data) { alert(data); } }); return false; }); }); </script>Whenevever I submit the form I get:
OPTIONS charge 405 Method Not Allowed
In my Payment API I have
[HttpPost] public HttpResponseMessage Charge(Payment payment) { //return Json }For my route I have
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapHttpRoute( name: "ActionApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); }Is there something wrong with my route?
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Ajax not posting to custom action
Jun 09, 2012 05:45 PM|LINK
Is you are cross site posting data?
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
RameshRajend...
Star
7983 Points
2099 Posts
Re: Ajax not posting to custom action
Jun 09, 2012 06:17 PM|LINK
Pls check this
http://stackoverflow.com/questions/9169033/create-custom-actions-in-django-admin-site-not-list-actions
Thank u
JustPlaneCra...
Member
4 Points
12 Posts
Re: Ajax not posting to custom action
Jun 10, 2012 07:21 PM|LINK
Yes.
Is there something special I need to make this work? I have a site running on http://localhost:8060 calling the web api.
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Ajax not posting to custom action
Jun 11, 2012 03:12 AM|LINK
See CORS.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
JustPlaneCra...
Member
4 Points
12 Posts
Re: Ajax not posting to custom action
Jun 11, 2012 02:31 PM|LINK
Yup. Found the link while googling. Worked great!