Dynamic Select in Laravel 5.6, the second select is not loaded even though in the console I can see that the data is being brought

-1
  $(function(){
    $("#user_select").on('change', function (e) {
        console.log(e);
        var user_id=e.target.value;
        $.get('http://localhost/helpdesk/public/userasset/'+ user_id,function (data) {
            console.log(data);
            $('#assetselect').empty();
            $('#assetselect').append('<option value="0" disabled="true" selected="true">-- ACTIVO --</option>');

            $.each(data,function (index,assetObj) {
                $('#assetselect').append('<option value="'+ assetObj.id+'">'+ assetObj.model +'</option>')

            })
        });
    });
});

vista

   <div class="col-sm-4">
                            <select class="form-control show-tick" data-live-search="true" name="user_id" id="user_select">
                                <option value="">-- USUARIO --</option>
                                @foreach($users   as $user)
                                    <option value="{{$user->id}}">{{$user->first_name}} {{$user->last_name}}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-sm-4">
                            <select class="form-control show-tick" name="asset_id" id="assetselect">
                                <option value="0" disable="true" selected="true">-- Seleccione ACTIVO --</option>
                            </select>
                        </div>
    
asked by Marines Acosta Martinez 18.09.2018 в 19:57
source

1 answer

0

I think you are doing your $.each wrong since you are filling it with data and the $('#assetselect') must be filled with the answer of ajax , in which variable do you receive the answer from ajax?

    
answered by 20.09.2018 в 22:07