i want to create dinamic dropdown in laravel 5.1 with ajax.. please help me
my routes.php
use App\users_groups;
Route::group(['middleware'=>'auth'],function(){
Route::get('/', 'HomeController@index');
Route::get('home', 'HomeController@index');
Route::resource('users', 'UsersController');
Route::resource('instalasis', 'InstalasisController');
Route::resource('groups', 'GroupsController');
Route::resource('parameters', 'ParametersController');
Route::resource('forms', 'FormsController');`
**Route::get('ajax-subcat',function(){
$ins_code = Input::get('instalation_code');
$usergrup = users_groups::where('master_instalation_code','=',$ins_code)->lists('group_name','group_code');
return Response::json([$usergrup]);
});**
});
route for my dropdown is ajax-subcat
and then this is my view
<div class="form-group">
<label class="col-md-3 control-label" for="example-hf-email">Instalasi</label>
<div class="col-md-9">
{!! Form::select('master_instalasion_code',$formins,null,['class'=>'form-control','id'=>'instalation']) !!}
<span class="help-block">isikan Group</span>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="example-hf-email">Group / Laporan</label>
<div class="col-md-9">
{!! Form::select('user_group_code',['placeholder'=>'Entry..'],null,['class'=>'form-control','id'=>'instalation']) !!}
<span class="help-block">isikan Group</span>
</div>
</div>
and this my ajax for retrieving data
<script>
$('#instalation').change(function(e){
console.log(e);
var ins_code = e.target.value;
$.get('../ajax-subcat?instalation_code='+ ins_code,function(data){
$('#riskyy').empty();
$.each(data, function(key, value) {
console.log(data);
$('#riskyy')
.append($("<option></option>")
.attr("value",key)
.text(value));
});
});
});
</script>
when i get data from id instalation i get json data like this
[{"03":"Jartes","076":"DAta"}]
the data is true, but i can't to show it in select form
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire