Advertisement
Guest User

jquery autocomplete

a guest
Feb 1st, 2023
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. $(document).ready(function() {
  2.  
  3. $( "#search-input" ).autocomplete({
  4. source: function( request, response ) {
  5. var base_url = window.location.origin;
  6. var query = request.term;
  7.  
  8. if (query.length > 0) {
  9. $.ajax({
  10. url: `${base_url}/search/ajax`,
  11. dataType: "json",
  12. data: {
  13. q: query,
  14. },
  15. success: function( data ) {
  16. console.log(data.length)
  17. response(data);
  18. }
  19. });
  20. }
  21. },
  22. _renderItem: function(ul,item) {
  23. return $("<li>")
  24. .append("<div>" + item.title + "</div>")
  25. .appendTo(ul);
  26. }
  27. });
  28. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement