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

267
Vistas
Jquery select2 error while taking json data

I'm using jquery Select2 4.1.0-rc.0 This is my Javascitp code:

        $('#task_dname').select2({
        placeholder: 'Select an item',
//      tags: true,
//      cache: true,
        delay: 250,
        maximumInputLength: 20,
        minimumInputLength: 2,
        dataType: 'json',
        ajax: {
            type: 'post',
            url: 'query_list_tasks.php',
            data: function (params) {var post_data = {searching: params.term, query: 'task_list'}; return post_data;},
            processResults: function (data) {
                console.log(data);
            return {
              results: data.items
            };
          }
        }
      });;

PHP generating json:

while ($row = $result->fetch_assoc()) {
   $response[] =  array(
      "id" => $row['id'],
      "text" => $row['text']
   );
}

//echo json_encode($response);
echo '{ "results": '.json_encode($response).'}';

Json for processResults data (console.log):

{ "results": [{"id":"10","text":"Test1"},{"id":"11","text":"Test2"}]}

This seems ok but i get this error when i try to search something, and there is no options in select field showing up:

jquery.min.js:2 jQuery.Deferred exception: Cannot read properties of undefined (reading 'slice') TypeError: Cannot read properties of undefined (reading 'slice')

Something is missing or im just to stupid? I'm. stuck.

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