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

81
Views
How to add a tags to autocomplete - Jquery

I have an autocomplete drop down and i am trying to add a tags to the list. When i populate the availableTags array and run the project, it works fine as below

File.JS

var availableTags = [];
$(document).ready(function(){
$(function() {
    $( "#search-product" ).autocomplete({
      source: availableTags     
    }
    });
  });  
});


function getItems(token,id)
{  
     $.ajax({
        url: "/get/product/items",
        type: "POST",
        data: {
            _token: token,
            id:id,
        },
        success: (dataResult) => {
            availableTags.length = 0
            $.each(dataResult, function(index,products) {
              
               availableTags.push(products.name,products.price);

              }); 
        },
    });
}

Is there a way i can populate the the ul list with my a tags as below. This is what i have tried and when i run the project, it returns empty list.

Is there something i am doing wrong ?

JS

 function getItems(token,id)
    {  
         $.ajax({
            url: "/get/product/items",
            type: "POST",
            data: {
                _token: token,
                id:id,
            },
            success: (dataResult) => {
                availableTags.length = 0
                $.each(dataResult, function(index,products) {
                  
           availableTags.push( $(".ui-autocomplete").append('<li class="ui-menu-item" role="presentation"><a class="ui-corner-all" tabindex="-1">Apple & Samsung</a></li>'));
    
                  }); 
            },
        });
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have missing some syntax here:

var availableTags = [];
$(document).ready(function(){
    $( function() {
        $( "#search-product" ).autocomplete({
          source: availableTags
        });
    } );
});

In Success call back:

success: (dataResult) => {
    availableTags.length = 0;
    $.each(dataResult, function(index,products) {
       availableTags.push(products.name,products.price);
    });
    $("#search-product").autocomplete({
      source: availableTags
   });
}
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!