jquery - unable to push values into global array inside $.post() method -
i trying push returned data $.post method global array...please me how return entire array
var retval =[]; function returnoptionlist(optname){ $.post('getlisttypes',{"key":optname},function(data) { if (data.listnames == optname){ for(var i=0; i<data.values.length;i++){ retval.push(data.values[i]); } } }); return retval; }
use callbacks return data ajax call, not return
function returnoptionlist(optname, callback){ $.post('getlisttypes',{"key":optname},function(data) { if (data.listnames == optname){ for(var i=0; i<data.values.length;i++){ retval.push(data.values[i]); } } callback(retval) }); }
and call:
returnoptionlist(optname, data) { console.log(data); //your array })
Comments
Post a Comment