簡體   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'
    });    
});

當我使用的第一個數據getJSON()在第二getJSON()有一個錯誤說undefined請幫助我

使用承諾而不是這種嵌套。 很容易調試。

用異步等待調用它。

(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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM