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

157
Vistas
search autocomplete ajax in laravel

I am using ajax for live searching, but the problem is that It is shown only one result

when I am using .html() but when I am using append() it works but every word i write it to duplicate the results,

here is my code:

in controller,

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

ajax code in 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 Respuestas
Responde la pregunta

0

Yes you set your content in your loop statement, so it will only take the last content.

You can use some buffer variable :

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 Denunciar
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