You are not returning from an AJAX call, you are calling a callback function when this is done.
function gC(b,c,p) { var retval = []; $.getJSON('getmonths', 'b='+b+'&c='+c+'&p='+p, processData); } function processData(data){ var retval = []; $.each(data, function(key, val) { retval.push(val);
processData will be called when an AJAX call is made. This cannot return the value of another function, so all your logic should be inside this callback function.
UPDATE: you can also pass the callback function to gC when it is done.
function gC(b,c,p,f) { var retval = []; $.getJSON('getmonths', 'b='+b+'&c='+c+'&p='+p, function(d){ if(typeof f == 'function'){ f(d); } }); }
Then you call gC as follows:
gC(b,c,p,function(data){ var retval = []; $.each(data, function(key, val) { retval.push(val);
UPDATE2: I saw the code added to the question. This must be done in the callback.
gC(b,c,p,function(data){ var items = []; $.each(data, function(key, val) { items.push(val); }); $('td').each(function(index){