简体   繁体   English

如何在第二个 API 函数中访问第一个 API 函数中的变量

[英]how to access the variables in 1st API function in the 2nd API function

$.getJSON(url, function (data) {
    $.getJSON(url_wind, function (data2) {
        //do stuff with 'data' and 'data2'
    });    
});

when I use the data of the first getJSON() in the 2nd getJSON() there is an error saying undefined help me please当我使用的第一个数据getJSON()在第二getJSON()有一个错误说undefined请帮助我

Use the promises rather this nesting.使用承诺而不是这种嵌套。 it's easy to debug.很容易调试。

Call it like this with async await.用异步等待调用它。

(async function () {
    let data = await $.getJSON(url);
    let data2 = await $.getJSON(url_wind);
    console.log(data, data2);
})();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在第二次之后停止第一次 function? - How to stop doing 1st function after 2nd? 如何使用第一个 API 通话中的数据并在我的第二个 API 通话中使用该数据? - How to use a data from the 1st API call and use that in my 2nd API call? 如何将数据从第二数组添加到第一数组以在Google Visualization API中显示图表 - how to add data from 2nd array to 1st array for showing chart in google Visualization api 我想知道在第一种情况下,返回的 function 被称为中间件,但在第二种情况下,返回的 function 未被调用 - I want to know in the 1st case the returned function is called as a middleware,,but in the 2nd case the returned function is not called 简单的第一次点击触发第一个 function - 第二次点击触发另一个 function 不工作? - Simple on 1st click trigger first function - on 2nd click trigger another function not working? 在第一个结束后在后台进行第二个 API 调用 - Make 2nd API call in the background after 1st one ends in an observable Function 内的第二个 AJAX 调用发生在第一个 AJAX 调用之前 - Function inside 2nd AJAX call is happening before the 1st AJAX call 为什么第二个JS异步函数调用要等待第一个完成? - Why does 2nd JS async function call wait for 1st to finish? 如何搜索表的第二列而不是第一列 - How to search 2nd column of table instead of 1st column 如何根据从第一个下拉菜单自动更改的第二个下拉菜单更改第二个文本框的值? - How to change the 2nd textbox value based on the 2nd dropdown that is automatically changed from 1st dropdown?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM