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

156
Views
buscar autocompletar ajax en laravel

Estoy usando ajax para la búsqueda en vivo, pero el problema es que solo se muestra un resultado

cuando estoy usando .html() pero cuando estoy usando append() funciona, pero cada palabra que escribo para duplicar los resultados,

aquí está mi código:

en controlador,

 $patient = Patient::select('id', 'avatar') ->where('phone_number', 'like', '%' . $search_query . '%') ->orWhere('first_name', 'like', '%' . $search_query . '%') ->limit(15) ->get(); return $patient;

codigo ajax en blade

 $("#search-eng").keyup(function() { let search_query = $(this).val(); if (search_query != "") { $.ajax({ url: '{{ url('/appointment/calander_patient_search') }}/' + search_query, type: "GET", dataType: "json", success: function(data) { $("#search-eng-show-list").show(); if (data !== "") { $.each(data, function(key, value) { $('#search-eng-show-list').html( '<a data-id="' + value.id + '"' value.second_name + '</a>'); }); } if (data == "") { $('#search-eng-show-list').html( '<a><i "></i>No Record</a>' ); } }, }); } else { $("#search-eng-show-list").empty(); $("#search-eng-show-list").hide();; } });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Sí, configura su contenido en su declaración de bucle, por lo que solo tomará el último contenido.

Puedes usar alguna variable de búfer:

 if (data !== "") { var html = ''; $.each(data, function(key, value) { html += '<a data-id="' + value.id + '"' value.second_name + '</a>'); } $('#search-eng-show-list').html(html); // ....
about 4 years ago · Juan Pablo Isaza Report
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!