In the code below, I assign a value to a variable from JSON with this var tag = data[j]['text'];
and I output it with this console.log(tag);
(for testing) which works.
I try to push the values into an array with tags.push(tag);
but it WILL NOT WORK!
Why won't these values go into the array? I am just trying to get the contents of tag
into an array...
function GetAvailableTags() {
var url = '/TextCodes/TextCodes?key=';
var tagGroups = [];
$('.ui-autocomplete-input').each(function () {
var key = $(this).attr('id');
var tags = [];
//console.log(key);
$.getJSON(url + key, function (data) {
for (var j = 0, len = data.length; j < len; j++) {
var tag = data[j]['text'];
console.log(tag);
tags.push(tag);
}
});
console.log(tags.length);
for (var k = 0, len = tags.length; k < len; k++) {
console.log(tags[k]);
}
});
}
Thanks for your help.