简体   繁体   English

无法使用jQuery和Kohana php框架发布参数表

[英]Cannot post paremeters with jQuery and Kohana php framework

I'm trying to do a simple test post with jQuery in Kohana. 我正在尝试用Kohana中的jQuery做一个简单的测试文章。 Note that it works fine when I don't include any parameters. 请注意,当我不包含任何参数时,它工作正常。 But when I do, it stops working. 但是,当我这样做时,它将停止工作。 Here's the jQuery post: 这是jQuery帖子:

        var url = "home/order";
        $.post(url, { name: name}, function(data) {
                 alert('test');
        });

And here's the action method (never 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. 我一直在Asp.Net MVC中做这种事情。 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"?? 我是否需要添加一些东西以使其能够接受名为“ 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... 我从来没有在Asp.Net MVC中做过这样的事情,所以对我来说似乎不是,但也许在这里有所不同,我不知道...

Or am I not passing the parameters or receiving them the correct way for Kohana? 还是我没有传递参数或没有为Kohana正确接收参数?

All data passed to jQuery $.post method will go to Request::post() method. 传递给jQuery $.post方法的所有数据将转到Request::post()方法。 To access this data in your controller, use $this->request->post() . 要在控制器中访问此数据,请使用$this->request->post()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM