Can the result of an asynchronous request be used as a required parameter for another asynchronous request

var firstNum,secendNum;// defines global variables

    function first(){
        $.ajax({
            type:"POST",
            async:false,
            url:"http://120.132.230.256:8888/wallet/tran",
            data:data,
            success:function(data){
                if(data.code==1){
                    firstNum=data.info;
                }  
            }
        });
        return firstNum;//firstNum, "useId10086" 
    }
    function secend(){
        console.log(":"+firstNum);// "useId10086" 
        $.ajax({
            type:"GET",
            async:false,
            url:url,
            data:{id:firstNum},//firstNum,
                               //{id:"useId10086"}
                               //{id:firstNum}
                               //:{id:firstNum}
            success:function(data){
                if(data.code==1){
                    console.log(data);
                    secendNum = data.info.name;
                }
            }
        });
        return secendNum;
    }
    
    first();
    secend();
    //
    console.log(firstNum);// "useId10086" 
    console.log(secendNum);//

how can I achieve the result in the first () method and pass the value to the secend () request to get the data I want.
I hope all of you will answer your doubts and be very grateful!

Apr.09,2021

there are many solutions.
first, the popular solution in the past two years is Promsie, which uses the then function of promise to concatenate naturally.
second, I don't know which version of jQuery you are using. Starting with jQuery 1.5, the jqXHR object returned by $.ajax () implements the Promise interface, giving it all the properties, methods, and behaviors of Promise.
so, if the version supports it, you can concatenate promsie: directly

.
  

theoretically there's nothing wrong with your code (you call ajax Synchronize, so async:fasle, doesn't have the problem that other respondents say).
Please check whether the variables in data: {id:firstNum} in the secend method are spelled correctly

Menu