Cannot post paremeters with jQuery and Kohana php framework
I'm trying to do a simple test post with jQuery in Kohana. Note that it works fine when I don't include any parameters. But when I do, it stops working. Here's the jQuery post:
var url = "home/order";
$.post(url, { name: name}, function(data) {
alert('test');
});
And here's the action method (ne开发者_开发问答ver mind what it does, that's just nonsense, and I'm actually not using the parameter at all for this test, I just want it to return to show the alert for now so I see it works, but keep in mind that it works when I have no parameters):
public function action_order($name)
{
$view = new View('home/index');
$head = new View('home/head');
$this->template->head = $head;
$this->template->content = "TEST";
}
In the end I actually want two parameters here, but keeping it simple for now to try to get it to work at all.
So why doesn't this work? I've been doing this sort of thing in Asp.Net MVC all the time. Does it have something to do with routing? I have only the default route set up. Do I need to add something for it to be able to take parameters other than ones named "id"??
I never had to do anything like that in Asp.Net MVC, so it doesn't seem like it to me, but maybe that's different here, I don't know...
Or am I not passing the parameters or receiving them the correct way for Kohana?
All data passed to jQuery $.post
method will go to Request::post()
method. To access this data in your controller, use $this->request->post()
.
精彩评论