Populate multiple select box with jquery and laravel

jQuery AJAX
回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Populate multiple select box with jquery and laravel

文章 yehlu »

http://stackoverflow.com/questions/2298 ... nd-laravel

代碼: 選擇全部

Route::get('api/dropdown', function(){
            $input =Input::get('option');

                $prodotti= DB::table('prod')                
                    ->join('cat','cat.id_prod','=','prod.id')
                    ->where('cat.id','=',$input)
                    ->select('prod.id as idprod','prod.nome as nomeprod')
                    ->lists('nomeprod','idprod');


            return Response::json($prodotti);
            });

代碼: 選擇全部

jQuery(document).ready(function($){
    $('#a').change(function(){
        $.get("{{ URL::to('api/dropdown')}}", 
            { option: $(this).val() }, 
            function(data) {
                var model = $('#b');
                model.empty();

                $.each(data, function(index, value) {     
                     model.append($("<option />").val(index).text(value)); });
                });
          });
    });
});
回覆文章

回到「jQuery」