-2

I have two ajax that I want to call each other

if my first ajax is:

 xhrAddressPoll = $.ajax({
    url: api,
    data: {
        address: address,
        longpoll: longpoll
    },
    dataType: 'json',
    cache: 'false',
    success: function(data){

        updateText('yourHashes', (data.stats.hashes || 0).toString());
        updateText('yourPaid', (data.stats.paid));

    },
    });

if my second ajax is:

  $.ajax({
      url: CoinPriceAPI,
      dataType: 'json',
      cache: 'false'
  }).done(function(data1) {
      coinPrice = data;
  updateText('coinPriceBTC', coinPrice.price );
  });

how can my two ajax be called to each other?

example for output I want to like this:

updateText('yourPaidBTC', (data.stats.paid * coinPrice.price));

if I do like this:

 xhrAddressPoll = $.ajax({
    url: api,
    data: {
        address: address,
        longpoll: longpoll
    },
    dataType: 'json',
    cache: 'false',
    success: function(data){

        updateText('yourHashes', (data.stats.hashes || 0).toString());
        updateText('yourPaid', (data.stats.paid));
        updateText('yourPaidBTC', (data.stats.paid * coinPrice.price));

    },
    });

i got error with :

coinPrice is not defined

Thank you for your help!

gosdor xda
  • 23
  • 2
  • 5

1 Answers1

0

If I understand your question correctly you want to be doing something like this:

function ajax1() {

    $.ajax({
        ...
        success: function(ajax1Data) {
            ajax2(ajax1Data);
        }
    });
}

function ajax2(ajax1Data) {
    // call your second ajax here
}

As for you 'coinPrice is not defined' error, its sounds like you're in strict mode (good!) but you don't have a global coinPrice var that can be shared between functions.

Tom_B
  • 307
  • 2
  • 8