douwuying4709 2015-09-17 05:09
浏览 53

jQuery Ajax从PHP获取变量并设置值到其他jquery函数

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!

  • 写回答

1条回答 默认 最新

  • duandao3265 2015-09-17 05:14
    关注

    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);
      });
    
    评论

报告相同问题?

悬赏问题

  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了