0

我会很准确:我的$.postjQuery 函数和我的控制器中的一个动作有一个奇怪的问题。我是 PHP 新手,但我之前使用过 ASP.NET MVC,我希望它们是相似的。这是问题所在:

//This is my ajax call
$.post('get_random_photos', count, function(data) {
    ...
});

//This is my action
public function post_get_random_photos($count) {
    ...
}

//This is what I have in my routes.php
Route::post('photos/get_random_photos', 'photos@get_random_photos');

当我发出 ajax 请求时,我收到以下消息:

Missing argument 1 for Photos_Controller::post_get_random_photos()

我知道这可能可以解决,Input::get('count');但我宁愿将它count作为操作参数,就像我以前在 ASP.NET MVC 中所做的那样。有没有办法做到这一点?

4

1 回答 1

1

您的宁静路线需要在 url 中接收该计数,这是执行此操作的一种方式:

//This is my ajax call
$.post('get_random_photos/'+count, 'nothing', function(data) {
    ...
});

//This is my action
public function random_photos($count) {
    ...
}

//This is what I have in my routes.php
Route::post('photos/get_random_photos/(:num)', 'photos@random_photos');
于 2013-06-15T04:05:43.050 回答