【发布时间】:2012-10-23 12:41:28
【问题描述】:
function test(){
var distance=null;
first();
second();
third();
alert(distance);//it shows null always because it take 2 second to complete.
}
function first(tolat, tolon, fromlat,fromlon){
// calulating road distance between two points on the map using any other distance caluculating apis.
distance=dis; // update the value of distance but it takes 2 second to complete.
}
function second(){}
function third(){}
我的代码中有这种情况,现在在第一次和第二次完成执行之前调用了很多次函数三并且距离值没有更新。
【问题讨论】:
-
检查 jQuery when() 函数。 api.jquery.com/jQuery.when
-
也许你可以从另一个函数调用一个函数?
-
最好的方法完全取决于“任何其他距离计算 api”在做什么。
-
我已经从这个问题中删除了 J 标签,因为这个问题与 J 语言无关。请在将来标记您的问题时更加小心。谢谢。
-
利用 jquery 队列。见stackoverflow.com/questions/1095263/…
标签: javascript jquery ajax