从getJSON调用的函数获取返回值 [英] Get returned value from function called by getJSON

查看:89
本文介绍了从getJSON调用的函数获取返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果$.getJSON()成功获取JSON数据,则将调用一个函数,如下所示.如何捕获返回的值output?

If $.getJSON() succeeds in getting the JSON data, then a function is called, as shown below. How do I catch the returned value output?

$.getJSON(url, function(data) {
     // Do stuff with data if succeeds in getting the data
     return output;
     }
);

推荐答案

由于您希望在回调完成时调用另一个函数,因此应在回调本身中执行此操作.它是异步调用的,结果不在下一行.所以:

Since you want to invoke another function when the callback finishes, you should do that in the callback itself. It is invoked asynchronously and the result is not there on the next line. So:

$.getJSON(url, function(data) {
     // Do stuff with data if succeeds in getting the data
     $.getJSON(data, function() { .. });
  }
);

这篇关于从getJSON调用的函数获取返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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