creativetimofficial / ct-material-dashboard-pro

Material Dashboard Pro - Premium Bootstrap 5 Admin
https://demos.creative-tim.com/material-dashboard-pro/pages/dashboards/analytics
116 stars 28 forks source link

Problem with loading select option #234

Closed s3325238 closed 5 years ago

s3325238 commented 5 years ago

Hello team,

As the title said, I have that problem. I can fetch the data from laravel controller perfectly and can also console log the data. However, I cannot see the option tag within select.

This is my code for select option:

<div class="col-md-12"> <div class="row"> <label class="col-sm-2 col-form-label">Role</label> <div class="col-sm-8"> <div class="form-group"> <select class="selectpicker" name="roleSelect" id="roleSelect" data-size="10" data-style="btn btn-primary btn-round" title="Role required" required="true"> <option disabled selected>Select role</option> </select> </div> </div> <label class="col-sm-2 label-on-right"> Some text </label> </div> </div>

And this is the code from ajax within the page var formOption = "" ; var mySelect = $('#roleSelect'); $.ajax({ url:'{!! route('api.role.data') !!}', method:'get', // dataType:'json', success:function (role) { // alert(role) // $('#defaultRole').val(role.role_name) $.each(role,function (index,roleData) { $("#roleSelect").append('<option value='+roleData.id+'>'+roleData.role_name+'</option>'); // formOption += ""; // Data load successfull - problem with append to select tag }); // mySelect.html(formOption); console.log($('#roleSelect')); // alert(formOption);

} }); API code: $roles = Role::All(); return $roles; I also include the evidence of page loading. Please help me.

Screen Shot 2019-05-04 at 8 52 50 PM
s3325238 commented 5 years ago

Here is console log in case you need it

Screen Shot 2019-05-04 at 9 13 02 PM
s3325238 commented 5 years ago

btw, my purchase email for this product is: leonguyen0202@gmail.com

Moreover, I also leave a comment inside this product page via your website

Screen Shot 2019-05-04 at 9 15 47 PM
groovemen commented 5 years ago

Hello @s3325238,

Thank you for using our products, due to I don't have any experience with Ajax, I can direct you to these references: https://stackoverflow.com/questions/43515919/loading-bootstrap-select-picker-using-ajax https://developer.snapappointments.com/bootstrap-select/

Best, Stefan