Skip to content Skip to sidebar Skip to footer

How To Pass Ajax Result As Parameter To Another Ajax To Make A Request

I want to pass ajax result id to another ajax so that it can call the other endpoint. I need to first get the id and name of the fund. then pass is back to another endpoint to get

Solution 1:

You can write the code as JavaScript function in a separate .js file and call that function from the html page. Then inside the function you can call other functions that will perform other ajax requests.

Solution 2:

you can use callback fun to call another API end point

<body><divclass="container"><divclass="text-center funds-item-container"><h3>Get Prices</h3></div></div><script>
    $(document).ready(function () {
    $.ajax({  
        type: 'GET',
        url: 'http://datarecapture.premiumpension.com:8089/api/Prices/GetAllFundNames',
        contentType: "application/json",
        success: function(resp) {
        console.log('hello: results', JSON.stringify(resp))


          for (var i = 0; i < resp.result.length; i++) {
            console.log('hello: results', JSON.stringify(resp.result[i].FUND_NAME));
                callbackfun(resp.result[i].FUND_ID)

            $('.funds-item-container').append(
               `<div><h5>Price ${i+1}</h5>
                  <a id='#price${i+1}'>
                   <a href="${resp.result[i].FUND_ID}"> ${resp.result[i].FUND_NAME}</a>
                  </p>
                </div><hr>`
            );
          }
        },

        error: function(xhr, status, error){
          debuggervar errorMessage = xhr.status + ': ' + xhr.statusTextalert('Error - ' + errorMessage);
        }
});




});

 functioncallbackfun(resp)
{
    $.ajax({  
            type: 'GET',
            url: 'http://datarecapture.premiumpension.com:8089/api/Prices/GetCurrentFundPrice?fundId=' +resp ,
            contentType: "application/json",
            success: function(resp) {
              console.log(resp);

             for (var i = 0; i < resp.result.length; i++) {
               //console.log('hello: results', JSON.stringify(resp.result[i].FUND_NAME));


                $('.funds-item-container').append(
                   `<div><h3>'</h3>
                      <a id='#price${i+1}'>
                       ${resp.result[i].FUND}
                      </p>
                    </div><hr>`
                );
          }
},

            });
}

</script></body>

Post a Comment for "How To Pass Ajax Result As Parameter To Another Ajax To Make A Request"