Untitled
unknown
plain_text
a month ago
1.2 kB
1
Indexable
Never
$(document).ready(function(){ $('#category-input').on('keyup', function() { let query = $(this).val(); if (query.length > 0) { $.ajax({ url: "{{ route('autocomplete') }}", method: 'GET', data: { query: query }, success: function(data) { $('#suggestions').empty(); if (data.length > 0) { data.forEach(function(category) { $('#suggestions').append('<div class="autocomplete-suggestion" data-id="' + category.id + '">' + category.name + '</div>'); }); } else { $('#suggestions').append('<div class="autocomplete-suggestion">No se encontraron resultados</div>'); } } }); } else { $('#suggestions').empty(); } }); // Selección de una categoría desde las sugerencias $(document).on('click', '.autocomplete-suggestion', function() { let categoryName = $(this).text(); $('#category-input').val(categoryName); $('#suggestions').empty(); }); });
Leave a Comment