Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript asynchronous Function Call : Retrieve calling function paramters in callback function

How can I get the user state in Javascript callback function ? Like I have a Javascript funciton making an asynchronous call as follows. Now In callback function I need to access userstate. How can I do this? In Silverlight we have userstate kind of thing. Do we have same kind of mechanism in Javascript as well. Please assist.

Note: I dont want to make use of Global variable as Func1() will be executed in a For Loop.

   function Func1() {
       var userState = "someValue";
       geocoder.asyncCall(parameters , CallBack);
   }


   function CallBack(result) {

       // Use result
       // How to access userState in this function
   }
like image 683
Abhishek Gahlout Avatar asked Jan 31 '26 19:01

Abhishek Gahlout


1 Answers

Try this code:

function Func1() {
   var userState = "someValue";
   geocoder.asyncCall(parameters ,function(){ 
      CallBack(userState);
   });
}


function CallBack(result) {

   // Use result
   // How to access userState in this function
}

update

function PlotAddressOnMap(address) { 
   var address = address; 
   var userState="userState";
   geocoder.geocode({ 'address': address }, CityDetailsReceived(userState)); 
} 

function CityDetailsReceived(userState) {
   return function(results, status){
      //your code
   }
} 
like image 167
pktangyue Avatar answered Feb 03 '26 08:02

pktangyue