Fill in combobox via Jquery

Asked

Viewed 189 times

0

I have the following html combobox:

<div class="form-group col-lg-6 row">
   {{ Form::select( 'state',array( 0 => '' ),null, array( 'class' => 'form-control', 'data-placeholder' => 'State','id' => 'state' ) ) }}
</div>

I’d like to populate it with the Bootstrap + Chosen with the following jquery block:

$(document).ready( function () {
            var token = $('#token').val();
            var estados = $('#state');

            $.ajax({
                url : './estados',
                dataType : 'json',
                type : 'post',
                data : {
                    _token : token
                },
                success : function ( data ) {

                    estados.find('option').remove();
                    estados.append( $('<option>').val( 0 ).text( '' ));
                    //console.log( data );
                    $.each(data, function (i, j) {
                        console.log( j.descricao );
                        var option  = $('<option>').val( j.sigla ).text( j.descricao ) ;
                        estados.append( option );
                    });
                    estados.trigger('chosen:updated');
                }
            });
        });

But nothing happens. Since console.log displays the data normally.

In direct PHP I get popular, but I would like to use in Laravel.

  • tried it like this $.ajaxSetup({ cache: false });

  • What is the cache : false ?

  • When setting the property of the false cache jQuery will attach a date/time stamp to the URL, then the browser does not cache it (as the URL is unique to each request), if in the console it is saying that it worked, sometimes the browser is cached in the information

  • Didn’t work either

  • It only works if I bring it straight from the controller

  • Even using <select><option> doesn’t work

  • Nothing? I haven’t figured it out yet

  • I was able to fill in via jquery

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.