jquery ajax success function returns undefined variable -
i trying simple set variable results of jquery ajax call have set non synchronous.
all attempts far return undefined , don't know why.
i understand cannot use synchronous call code have moved on before results returned.
here's basic code:
$(document).ready(function() { var test = visitordata(); console.info(test); });
and ajax call:
function visitordata() { var chartvalues = []; var chartlabels = []; //console.info("chartvalues:"+chartvalues); //return "test"; $.blockui({message: '<h1><img src="/img/icons/icon_loading_red.gif" /> please wait - grabbing data...</h1>'}); $.ajax({ url: '/visitdata', type: 'get', async: false, datatype: "json", success: function (data) { visitors = data; console.warn(data); (var k in visitors){ if (typeof visitors[k] !== 'function') { chartvalues.push(visitors[k].average_order); } } console.info(chartvalues); return chartvalues; } }); }
the values being obtained in success function , chartvalues exists before return. no data given original call.
not sure why , need do?
Comments
Post a Comment