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

181
Views
getting images from ajax and displaying them in select2

I'm trying to display images, along with the name, and ID from a database and displaying them in a select2 dropdown. I see in the console that the objects are coming through, but they are not displaying them?

Thank you for your help.

<select style="width: 100%" id="organization" class="form-control" name="organization-id">
 <option value="" disabled  selected>Find an organization</option>
</select>


function formatData (data) {
        if (!data.id) { return data.name; }
        var $result= $(
            '<span><img src='+ data.avatar +'/> ' + data.name + '</span>'
        );
        return $result;
    };

$( "#organization" ).select2({
        ajax: {
            url: "{{route('organization-search')}}",
            type: "get",
            dataType: 'json',
            delay: 250,

            data: function (params) {
                return {
                    search: params.term // search term
                };
            },
            processResults: function (data) {
                return {
                    results: data
                };
            },
            templateResult: formatData,
            templateSelection: formatData,
            cache: true
        }

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