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
}
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With