user2965840
user2965840

Reputation: 1

jQuery Ajax Get Variable From PHP and Set Value To other jquery function

i'm trying to get a value from a get ajax request and put it into another jquery function

  $(document).ready(function(){
    var callAjax = function(){
      $.ajax({
        method:'get',
        url:'getrecord.php',
        success:function(data){
          $("#sample").html(data);
        }
      });
    }
    setInterval(callAjax,10000);
  });

in getrecord.php i just have an echo rand number which i need to place in this other function -where number 10 is placed- instead of be printed in sample div

$('#ten').prop('number', 10).animateNumber({
        number: 100
    },
    2000
);

how can i do it? thanks in advance!

Upvotes: 0

Views: 69

Answers (1)

Barmar
Barmar

Reputation: 780869

Put the other code in the success callback.

  $(document).ready(function(){
    var callAjax = function(){
      $.ajax({
        method:'get',
        url:'getrecord.php',
        success:function(data){
          $("#ten").prop('number', data).animateNumber({
            number: 100
          }, 2000);
        }
      });
    }
    setInterval(callAjax,10000);
  });

Upvotes: 3

Related Questions