I have an issue with my javascript not waiting for the return of the call. I already now that javascript is asynchronous so I would like to know how to make this method call wait for the result. I do not have control over the first two snipper since they are uploaded by the user. I can use jquery or pure javascript. Advance thanks!
I have this javascript call
var value = somemethod("cmi.location");
/ /This is not getting set since it does not wait. alerts 'undefined'
alert(value);
and somemethod looks something like the code below,
function somemethod(element){
var result;
result = API1.GetValue(element);
return result;
}
API is a window object instantiated by doing the code below. I have access to the code snippets from this point on.
var API1 = new API();
API is an object in javascript which looks like this:
function API(){
};
API.prototype.GetValue=API_GetValue;
function API_GetValue(parameter){
$.ajax({
type:"POST",
async:false,
url:"method.do",
dataType:"xml",
data: {action: 'getValue', parameter: parameter, value: ''},
success:function(data){
//I am getting 0 here
return $(data).find('search').text();
}
});
}
you can also do something like this: