Laravel Ajax下拉filter

我正在尝试使用Ajax创建一个filter,我想在下拉列表中根据所选类别显示图像,只要它发生变化。 现在我在我的视图中显示所有图像,我想进行Ajax调用,返回过滤的$ images数组以在视图中显示。 但我卡住了。 我无法弄清楚如何正确地从控制器返回数据,所以我可以在视图中访问它。

使用index.blade.php中的下拉列表

{{ Form::open( array( 'route' => 'index.filter', 'method' => 'post', 'id' => 'form-filter' ) ) }} {{ Form::select('category', $categories, 'default', array('id' => 'categories')) }} {{ Form::close() }} 

路线

 Route::post( 'filter', array( 'as' => 'index.filter', 'uses' => 'MyController@filter' ) ); 

.js文件

 $( '#form-filter' ).change( function() { $.post( $( this ).prop( 'action' ), { "id": $( '#categories' ).val() }, function( data ) { alert(data); }, 'json' ); return false; } ); 

控制器

 public function filter() { Log::info(Input::get('id')); $id = Input::get( 'id' ); if($id) $images = Image::where('category_id', '=', $id); return Response::json($images); } public function index() { $images = Image::all(); $categories = ..\Models\Category::lists('name', 'id'); return View::make('index', array('images' => $images, 'categories'=>$categories)); }