使 AJAX “get"函数同步/如何得到结果? [英] Make AJAX "get" function synchronous / how to get the result?
本文介绍了使 AJAX “get"函数同步/如何得到结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了 $.get 函数的问题.url 包含 JSON
I'm experiencing a problem of $.get function. The url contains JSON
我的代码:
xyz = null
$.get('http://www.someurl.com/123=json', function(data) {
var xyz = data.positions[0].latitude;
});
alert(xyz);
//some more code using xyz variable
我知道 xyz
会提醒一个空结果,因为 $.get
是异步.
I know that xyz
will alert a null result because the $.get
is asynchronous.
那么有什么办法可以在这个get函数之外使用xyz
?
So is there any way I can use the xyz
outside this get function?
推荐答案
真正的答案是NO,但你可以使用这个:
The real answer is NO, but you can use this:
function useXYZ(){
alert(xyz);
}
xyz = null
$.get('http://www.someurl.com/123=json', function(data) {
xyz = data.positions[0].latitude;
useXYZ();
});
这篇关于使 AJAX “get"函数同步/如何得到结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文