javascript - Need to manipulate a global var, but can't in Ajax. Need a way around this -


http://pastebin.com/x5una1se

here's paste of bit of troubled coded.

i'm trying manipulate global variable "data" within jquery.get callback function in order format data , return data needed.

however, global variable not manipulated @ in callback function due ajax being asynchronous.

how can information need database , return variable i'm trying in code?

any direction appreciated!

thanks

i think missed points asynchroneus , callback know words, don't know how handle these behavior.

asynchroneus means have use callbacks -» means code must efficient, don't put things 1 after others. have functions, of these functions 1 thing, , call specified callback when have finished meant to.

what have not expecting return mappoints calling callback function when finished manipulate datas.

just little example of using callbacks

function displaypoint(data) {     //display points }  function callserver(callback {     ajaxcall(url, function(data) { datahandler(data, callback); } ); }  function datahandler(data, callback) {     // modify data      callback(data); }   // process callserver(displaypoint);   /*** call callserver passing displaypoint callback callserver perform ajax call. result handle anonymus function. function call datahandler function, passing datas server, , callback function given callserver ( displaypoint ) datahandler modify datas, call callback function, passing datas.  don't need global var anymore, , thing ***/ 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -