I'm trying to generate an array from ajax result. When my code runs it populates the list. But once the ajax call is done, and I start iteration of that populated list, it doesn't output anything.
When I put it in debugging mode I can see that the array "tlitems" is getting populated.
But then after last item is added, it goes out.
var tlitems = [];
function GetTL() {
$.ajax({
type: 'GET',
url: '/PTL',
datatype: 'json',
headers: headers
}).done(function(ptl) {
$.each(ptl, function(key, value) {
var pid = this.pid;
var owner = this.strowner;
var dbtstamp = this.db_tstamp;
var tlt = "pi";
item = {}
item["_pid"] = personid;
item["_owner"] = owner;
item["_dbtstamp"] = dbtstamp;
item["_tlt"] = tlt;
tlitems.push(item);
});
}).fail();
$.each(tlitems, function(k, v) {
alert("Key: " + k + ", Value: " + v);
})
};
It should alert with K:V. But it just comes out.