Below is my code. For the moment all I'm trying to do is return anything at all just so I understand the JQuery side of things.
Controller:
public class WeBuyAlmostAnythingController : SurfaceController
{
[HttpPost]
public ActionResult FirstAjax(string a)
{
return Json("chamara", JsonRequestBehavior.AllowGet);
}
}
JQuery calling Controller Method
Hi All,
I'm trying to call a Controller Method using JQuery . But every time I'm getting something along the lines of:
WeBuyAlmostAnythingController /FirstAjax 404 (Not Found)
Below is my code. For the moment all I'm trying to do is return anything at all just so I understand the JQuery side of things.
Controller:
JQuery:
Currently all I'm getting is error as the errorFunc is being called.
Thanks, Lewis
Am i pointing to the controller correctly?
Do i need to point to Controllers/WeBuyAlmostAnything.cs? Or do i need to add some routing?
Thanks, Lewis
After reading up on routing I understand now that the route should be the following:
/umbraco/surface/WeBuyAlmostAnythingController/FirstAjax
I have tried this and I'm still getting the same error.
Thanks, Lewis
What is the error exatly?
This is just a guess, but your surface control method takes in a string pram, but your not passing that in the Ajax request.
Could it be that its not finding the method becuase you not passing the prams to match it.
Try creating another method without any prams and see if that gets called.
If you post the error it might be easier for someone to give you a pointer.
Hi Lewis,
It is probably the parameter field not matching..
Change "param" to "a" and pass a value.
Also, this could be changed to a GET request for simplicity and testing.
Craig
I managed to get this working. I deleted everything and started again. The code below is the working code.
One question: Is there any downfalls to doing this with JQuery? Obviously older browsers or users who have JavaScript disabled wont seek the benefits.
Controller:
JQuery:
Any questions,
Ask away!
Thanks, Lewis
is working on a reply...