![](/img/trans.png)
[英]Laravel send data such as 1-2-3 by ajax and get Missing argument error
[英]Missing argument error when posting data through ajax (using Laravel)
我會精確地說:我在$.post
jQuery函數和控制器中的操作中遇到了一個奇怪的問題。 我是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');
解決Input::get('count');
但我寧願具有count
作為動作參數,為我所用的ASP.NET MVC做。 有什么辦法可以做到這一點?
您的靜態路由需要在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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.