狐狸.fox 2018-03-20 09:51 采纳率: 0%
浏览 33

混响两个异步调用

I am calling the twitch TV API to get users info from one endpoint and I want also to call another endpoint in the same API to check if those users are streaming live or not, but only if the first ajax call is successful. Can anyone give me a hint on how to do it?? My first call below:

var getUserInfo = $.ajax({
    type: "GET",
    url: "https://api.twitch.tv/helix/users/?login=ESL_SC2&login=freecodecamp&login=noobs2ninjas",
    // contentType: ('application/x-www-form-urlencoded; charset=UTF-8'),
    crossDomain: true,
    headers: {
        "Client-ID": "5k4g3q59o69v6p9tudn39v50ro1mux",
    },
    dataType: "json",
    success: function (json) {
        console.log(JSON.stringify(json, null, 2));
    },
    error: function () {
        console.log("OOPS!!!");
    },
})
  • 写回答

2条回答 默认 最新

  • weixin_33691598 2018-03-20 09:53
    关注

    The success function only runs if the call was successful.

    Trigger the code for the second request from the success function.

    评论

报告相同问题?