Reload AJAX data every X minutes/seconds, jQuery

后端 未结 2 1615
情歌与酒
情歌与酒 2020-12-10 16:01

I programmed a CMS that has a log of who has recently logged into the system. Presently, this data is fed into a jQuery UI tab via Ajax. I would like to put this information

2条回答
  •  死守一世寂寞
    2020-12-10 16:25

    The simplest way (whether its the best way is subjective - for the use case you've presented I'd say its fine) would be to do:

    var updateInterval = setInterval(function() {
      $('#whereIWantToDisplayIt').load('/thePathToThatScript.php');
    },30*1000);
    

    Every 30 seconds, this would load the output of your PHP script, and put that output into the element with ID = whereIWantToDisplayIt

    I prefer Seb's answer though.

提交回复
热议问题