i need to append some options in select element, What i am doing wrong here,
Remember:
I am using jquery chosen plugin.
$(document).ready(function(e) {
$("#my_select").chosen();
get_data()
});
function get_data() {
$.ajax({
url: "<?=site_url('controller/function')?>",
success: function(result){
result = $.parseJSON(result);
$.each(result, function(i, v) {
//alert('inside')
$('#my_select').append("<option value='"+v.id+"'>"+v.name+"</option>");
});
$("#my_select").trigger("chosen:updated");
}
});
}
Json response is absolutely fine,
[{"id":"2","name":"name1"},{"id":"3","name":"name2"}]
While my html is,
<select id="my_select" name="my_select" data-placeholder="Select type">
<option value=""></option>
</select>