Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
JQuery select2 set default value from an option

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;
        });
      }
  })()
};

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!