I wanna set a default options from result data and my code isn't working. I try to console.log(data) to check the data, but the data is empty. I think, there is a wrong code in mine, at the String.create. I would like to know why this is the case.
var file_bast = String(result.file_bast);
var fileid = Strings.create("<?=$base_url.$page? >/data/fetch_data_file_update/{filebast}", {filebast:file_bast});
$.ajax({
type: 'GET',
url: fileid
}).then(function (data) {
console.log(data);
$('#file_bast').append(new Option(data.id, data.text, true, true)).trigger('change');
$('#file_bast').trigger({
type: 'select2:select',
params: {
data: data
}
});
});
var Strings = {
create : (function() {
var regexp = /{([^{]+)}/g;
return function(str, o) {
return str.replace(regexp, function(ignore, key){
return (key = o[key]) == null ? '' : key;
});
}
})()
};