代碼: 選擇全部
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)); });
});
});
});
});