让AJAX和QUOT;获得"功能同步/如何得到的结果? [英] Make AJAX "get" function synchronous / how to get the result?

查看:160
本文介绍了让AJAX和QUOT;获得"功能同步/如何得到的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的$不用彷徨功能的问题。 该URL包含JSON

I'm experiencing a problem of $.get function. The url contains JSON

我的code:

my code:

 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 将提醒一个空的结果,因为 $。获得同步

I know that xyz will alert a null result because the $.get is asynchronous.

那么,有没有办法,我可以使用 XYZ 此得到功能之外?

So is there any way I can use the xyz outside this get function?

推荐答案

真正的答案是,但你可以用这样的:

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和QUOT;获得"功能同步/如何得到的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆