Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda