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

273
Views
Error Jquery select2 al tomar datos json

Estoy usando jquery Select2 4.1.0-rc.0 Este es mi código Javascitp:

 $('#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 generando json:

 while ($row = $result->fetch_assoc()) { $response[] = array( "id" => $row['id'], "text" => $row['text'] ); } //echo json_encode($response); echo '{ "results": '.json_encode($response).'}';

Json para los datos de los resultados del proceso (console.log):

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

Esto parece estar bien, pero recibo este error cuando intento buscar algo, y no aparece ninguna opción en el campo de selección:

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

¿Falta algo o soy demasiado estúpido? Estoy. atascado.

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!