javascript - Print a specific attribute from an object within an AJAX retrieved object list? -


i'm using ajax call return list of objects database in json format. these displayed part of autocomplete text input. problem want output/display name attribute of each object within list.

$(function() {     $("#ingredient-search").autocomplete({         source : function(request, response) {             $.ajax({                 url : "searchcontroller",                 type : "get",                 data : {                     term : request.term                 },                 datatype : "json",                 success : function(data) {                     response(data);                 }             });         }     }); 

the actual ajax & on works fine. i'm unsure how can iterate through every element within 'data' , output name attribute each json object.

thanks

without knowing json structure, try this.

$.each(data,function(key,val){     console.log(val.name); }) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -