Create a dependent select?

0

I'm trying to create a dependent select with laravel, but I can not get the second select to work, the response returns empty.

This is my script

<script type="text/javascript">
$(document).ready(function(){
     $.ajaxSetup({
        headers:{
            'X-CSRF-TOKEN' : $('meta[name="csrf-token"]').attr('content')
        }
    });
    $('#rol').change(function(){
        $.get("{{ url('select/{id}')}}",
        { option: $(this).val() },
        function(data) {
            console.log(data)
            $('#user_id').empty();
            $.each(data, function(key, element) {
                $('#user_id').append("<option value='" + key + "'>" + element + "</option>");
            });
        });
    });
});     

And my route is as follows

Route::get('select/{id}', function($id){
    $user_id = DB::table('users')->where('role_id','=','select/')->pluck('name');
    return response()->json($user_id);
});
    
asked by Jose 24.05.2018 в 01:05
source

0 answers